I have the following utility class:
public class MyUtils{
public static <T> List<? extends T> getList(Class<T> clazz){
}
}
And the class that uses the method:
public class MyClass<T>{
public static List<MyClass<?>> values(){
return (List<MyClass<?>>) MyUtils.getList(MyClass.class);
}
}
It is not clear why it is not safe? The result of the method cannot be assigned to such a variable:
List<MyClass<? extends Integer>> lst = MyClass.values();
The only way we can assign the result of a method is as follows:
List<MyClass<?>> dsss = MyClass.values();
So, what is the runtime error such a lithiation can lead to?
source
share