Java provides me by <? extends class>
a way of filtering the java classes that you can use to
build in this case the new HashMap, for example:
I can do that:
Map<String,? extends Serializable> map1 = new HashMap<String,String>();
It is correct, because String implements Serializable, so the compiler let me do that.
But when i try to do it:
Map<String,GenericClass<? extends Serializable>> map2 = new HashMap<String, GenericClass<String>>();
Being the GenericClass as it:
public class GenericClass<T>
{
.
.
.
}
The compiler throw an error saying:
Type mismatch: cannot convert from HashMap<String,GenericClass<String>> to Map<String,GenericClass<? extends Serializable>>
I would like to know, what is happen?
Maybe the compiler cannot detect the extends class being part of a generic type.
new HashMap<String, GenericClass<String>();
– Mujik