When I try to assign an object of type List<List<Object>>
to a variable with a wildcard parameterized type List<List<?>>
, I get the error "incompatible types: List<List<Object>>
cannot be converted to List<List<?>>
".
Example:
List<List<Object>> x = new ArrayList<>();
List<List<?>> y = x; // Error
On the other hand, assigning an object of type List<Object>
to a variable of type List<?>
work perfectly fine.
Example:
List<Object> x = new ArrayList<>();
List<?> y = x; // Works fine
Why is that? Why does it work for List<?>
but not for List<List<?>>
?
Environment: JDK 7, Netbeans 8