I have a class B and C which both extends class A:
public class B extends A {...}
public class C extends A {...}
How can I use Java generics with a HashMap this way?
B b = new B();
C c = new C();
Map<String, ? extends A> map = new HashMap<String, A>();
map.put("B", b);
map.put("C", c);
Eclipse always shows an error:
The method put(String, capture#1-of ? extends A) in the type Map is not applicable for the arguments (String, B)
and
The method put(String, capture#1-of ? extends A) in the type Map is not applicable for the arguments (String, C)