Let's consider a class:
public class Foo<T> {
public List<String> list = new ArrayList<>();
}
that I'm passing as a parameter to a method.
I have a problem understanding why here the type String isn't resolved:
public void test(Foo t) {
t.list.get(0).contains("test");
}
and the t.list is treated as List<Object> while here everything works just fine:
public void test(Foo<?> t) {
t.list.get(0).contains("test");
}
and t.list is List<String>.
The other questions about Type Erasure that have been linked, approach the problem from a different angle. Without knowing the answer to my own question I failed to see the connection and it is why I do not think this question is a duplicate.