why does
public interface ArrayOfONEITEMInterface <T extends ONEITEMInterface>{
public List<T> getONEITEM();
}
compile, but not
public interface ArrayOfONEITEMInterface <? extends ONEITEMInterface>{
public List<?> getONEITEM();
}
what is the difference between ? and T in class and method signatures?
?is a wildcard and means any subclass ofONEITEMInterfaceincluding itself.Tis a specific implementation ofONEITEMInterfacein this case.Since
?is a wildcard, there is no relation between your?in the class declaration and the?in your method declaration hence it won’t compile. JustList<?> getONEITEM();will compile though.The first scenario means the entire class can handle exactly one type of
Barper instance.The second scenario allows each instance to operate on any subtype of
Bar