M
Mark Space
I got to thinking about the last generics question, and I don't
understand why the following doesn't work.
Given a list that holds some type of Class:
List<Class<String>> ls = new ArrayList<Class<String>>();
Why can't I assign this to a List that holds any type of Class?
List<Class<?>> al1 = ls; // oops
List<Class<?>> al2 = (List<Class<?>>) ls; // oops
Looking at the raw types, it seems this should work. al1 holds any type
of Class, and ls has a type of class. Yet there appears to be no way to
assign them. I don't know if this is a good idea, I merely want to
understand generics a little better.
understand why the following doesn't work.
Given a list that holds some type of Class:
List<Class<String>> ls = new ArrayList<Class<String>>();
Why can't I assign this to a List that holds any type of Class?
List<Class<?>> al1 = ls; // oops
List<Class<?>> al2 = (List<Class<?>>) ls; // oops
Looking at the raw types, it seems this should work. al1 holds any type
of Class, and ls has a type of class. Yet there appears to be no way to
assign them. I don't know if this is a good idea, I merely want to
understand generics a little better.