If I have a class:
public class GenericClass<TBlah extends Number> {
public List<String> getList() {
return null;
}
}
When I attempt to use that method from another class:
public class OtherClass {
public void test() {
GenericClass a = null;
for (String s : a.getList()) {
}
}
}
Why does a.getList()
return a List<Object>
until I change the line above the for loop to:
GenericClass<Number> a = null;
At which point a.getList() returns a List<String>
like it should do?
Edit: I don't understand why the contract specified by getList()
should be affected whatsoever by how I declare my variable 'a'. getList()
always returns a List<String>
, it doesn't matter what TBlah is.