There is a generic class:
class Test<T> {
T genericTypeField;
List<String> list;
}
void method1(Test test) {
for (String value : test.list) { // Compiler error
}
// Correct
for (Object value : test.list) {
}
}
void method2(Test<?> test) {
// Correct
for (String value : test.list) {
}
}
It seems that if use a generic class in non-generic way, all generic fields in this class will lose the generic info.
Does the Java specification has any description about this?