I am confused by this code, which is supposed to not work (I think), but doesn't seem to work without errors.
When I put <T>next to the Person class, the wildcard in Arraylist does not behave as it is defined, in the code below the wildcard should work only for the superPerson class , but <T>next to the Person class, it accepts all types for types (in this an example of this String). And also, in order for this to work, a person, when defined, should not have the specified type. Here is the code:
import java.util.ArrayList;
public class Person {
public static void main(String[] args) {
Human h = new Human();
h.al(new ArrayList<String>());
}
}
class Human<T>{
public void al(ArrayList<? super Person> a){
}
}
Thank:)
source
share