Recently I have come across the following error during compilation:
error: incompatible types: HashMap<Integer, HashMap<Object, Consumer<A>>> cannot be converted
to HashMap<Integer, HashMap<Object, Consumer<? extends B>>>
In this code, class A
is a direct subclass of B
.
This error occurred in the following snippet:
HashMap<Integer, HashMap<Object, Consumer<A>>> item = new HashMap<>();
HashSet<HashMap<Integer, HashMap<Object, Consumer<? extends B>>>> set = new HashSet();
set.add(item);
In attempting to resolve the error I have already tried removing the ? extends
bit from the HashMap
inside of the HashSet
, but the compiler kept throwing the error.