I do not understand why the below code works:
class MyMap<T> {
T value;
public void set(T value) {
this.value = value;
}
public T get() {
return value;
}
}
public class GenTest {
public static void main(String args[]) {
MyMap<String> map = new MyMap<String>(); // *
map.set("dog");
System.out.println(map.get());
}
}
But, if I change the marked * row to this:
MyMap<? extends String> map = new MyMap<String>();
then it does not compile.
It works also if I have this:
MyMap<? super String> map = new MyMap<String>();
Could You please help me? Thank you in advance!