I was reading the superb Java Generics FAQ by Angelika Langer when I read this source code example which I can't understand:
import java.util.List;
import java.util.ArrayList;
import java.lang.Number;
import java.lang.String;
import java.lang.Long;
class X<T extends List<? extends Number>> {
public void someMethod(T t) {
t.add(new Long(0L)); // error
Number n = t.remove(0);
}
}
I can't understand why the compiler can't infer that "Long extends Number" and match this with "? extends Number" before type erasure, making <? extends Number>
completely useless.
I already read the FAQ, so I'm looking for a simpler explanation as well as for alternatives, please.
Thanks in advance