I have simple generic parent class and suppose I have a list in this class:
public class GenericParent<N extends Number> {
protected List<String> s;
}
And also I have a child class that extend from this class like this:
public class GenericChild extends GenericParent {
private void testMethod() {
for (String o : s) {
//.....
}
}
}
I get Incompatible types in this line for (String o : s)
and tell me that s
is not String, it is object. but if I define my child class like this public class GenericChild extends GenericParent<Integer>
and declare my generic type, error goes away. Why this happened?
My question is not about what is the raw type and generic class. I define List of String in class that have generic type of Number and I don't get it why in child class I can't use my list of String that defined in parent.