class Demo {
<T> void gTee(List<List<T>> tl) {
tee(tl);
}
void tee(List<List<?>> tl) {
}
}
JDK 8 says
incompatible types: java.util.List<java.util.List<T>> cannot be converted to java.util.List<java.util.List<?>>
How come? I was of the opinion that the ?
wildcard stands for any type.
This is due to this behaviour of Java generics:
Even if
A
andB
are compatible types,SomeType<A>
is not compatible withSomeType<B>
A classic example of this is trying to assign a List<Cat>
to a List<Animal>
.
The same thing happens here. Normally, List<T>
can be assigned to List<?>
. But since you are assigning List<List<T>>
to List<List<?>>
, you can't.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With