I’m trying to figure out why I can’t I use super in a generic method declaration? See the example below, it doesn’t compile, but I’m not sure why.
public class A<E> {
public <T extends A> void test1(T t) { // Compiles fine
}
public <T super A> void test2(T t) { // Compilation error??
}
public <T super A> <T> void test3(T t) { // Compilation error??
}
}
class A {}
....
Think about it, if a method could have the signature
then it could take any object as argument. Why? Because, for example, you can always infer
TasObject(Objectis a supertype ofA), and any object is an instance ofObject, so it works. So declaring it this way would be pretty redundant. You could just writefor the same effect.