the JDK8, code is as follows:
public class Foo<E> {
public <T extends List> T get(T list) {
return null;
}
public void pass(Foo<?> foo) {
ArrayList arrayList = foo.get(new ArrayList());
}
public void broken(Foo foo) {
// Incompatible types,ArrayList
ArrayList arrayList = foo.get(new ArrayList());
}
}
The E
and get
methods of Foo
have different generic parameters T
, so whether or not to declare Foo
to be generic should not affect the get
method.
is this intentional by the JAVA author for some reason, or is the compiler incapable of inference?