D
David Harrigan
Hi,
First the code:
public interface A {
}
public class B implements A {
}
public class C {
public static void main(String[] args) {
new C().doIt();
}
public void doIt() {
Map<String, ? extends A> a = new HashMap<String, A>();
a.put("A Test", new B());
}
}
This won't compile, specifically at line "a.put..." because it says (in
eclipse):
"The method put(String, capture-of ? extends A) in the type Map<String,
capture-of ? extends A> is not applicable for the argumentes (String,
B)"
Why? I'm confused...
I thought I was saying that I want a map that takes a key with any
value that extends (or implements) A, and since B implements A it
should be happy....
Why doesn't this work?
Thanks
-=david=-
First the code:
public interface A {
}
public class B implements A {
}
public class C {
public static void main(String[] args) {
new C().doIt();
}
public void doIt() {
Map<String, ? extends A> a = new HashMap<String, A>();
a.put("A Test", new B());
}
}
This won't compile, specifically at line "a.put..." because it says (in
eclipse):
"The method put(String, capture-of ? extends A) in the type Map<String,
capture-of ? extends A> is not applicable for the argumentes (String,
B)"
Why? I'm confused...
I thought I was saying that I want a map that takes a key with any
value that extends (or implements) A, and since B implements A it
should be happy....
Why doesn't this work?
Thanks
-=david=-