Reputation: 565
what parameterized type should be for the "List" below?
List<Class<?>> supportedClasses = Arrays.asList(String.class, Integer.class, Long.class);
I tried
also
but they all have grammer error
Upvotes: 0
Views: 95
Reputation: 2907
This error occurs in Java 7 because the compiler cannot infer the type of the list returned from Arrays.asList
. JEP 101, released in Java 8, adds this functionality. The workaround for Java 7 is to explicitly specify the method type parameter:
List<Class<?>> supportedClasses = Arrays.<Class<?>>asList(String.class, Integer.class, Long.class);
Upvotes: 0
Reputation: 79105
Since the elements of your list are of type, Class
, your list should be of type, List<Class<?>>
List<Class<?>> supportedClasses = Arrays.asList(String.class, Integer.class, Long.class);
Upvotes: 5