This is my code:
private <T,L extends ArrayList<? extends T>> L Foo(L<T> list1) {
L list2 = new ArrayList<T>();
//more code
}
I'm using IDEA and get the following error message for the method parameter:
Type 'L' does not have type parameters
and the following error message for creating the ArrayList:
Incompatible types. <br>Required: L <br> Found: java.utils.ArrayList<T>;
Why does this happen? L
extends ArrayList so it should have the same type parameters right?
It's not known if ArrayList<T>
is an L
. For example, L
could be a MyArrayListImpl<T>
.
I think this is what you want:
private <T> List<T> Foo(List<T> list1) {
List<T> list2 = new ArrayList<T>();
//more code
}