Given this code:
List<Integer> ints = new ArrayList<Integer>();
// Type mismatch:
// cannot convert from Class<capture#1-of ? extends List> to Class<List<Integer>>
Class<List<Integer>> typeTry1 = ints.getClass();
// Type safety:
// Unchecked cast from Class<capture#2-of ? extends List> to Class<List<Integer>>
Class<List<Integer>> typeTry2 = (Class<List<Integer>>) ints.getClass();
// List is a raw type. References to generic type List<E> should be parameterized
Class<? extends List> typeTry3 = ints.getClass();
Is there a way to get the Class
of a List<Integer>
without an error or warning? I can suppress the warnings easily enough, but if Java requires me to suppress a warning for this valid code, I am very disappoint.
On the other hand, if warning suppression is the only way, what is the safest to suppress?