I think I made some mistake while writing my code. I have a class MyClass that implements Interface, now I've a method that is generic for List of Interface as a parameter. I want to use my method by passing a List. I can't cast from List to List (that I assumed I could). So, what can I do to make my code work? here an example:
List<MyClass> lista = returnMyClassList();
myMethod((List<Interface>) lista); //this doesn't work
//myMethod signature
public void myMethod(List<Interface> struttura);
Thanks for helping.
Use an upper bound of Interface
for the type: <? extends Interface>
.
Here's some compilable code that uses classes from the JDK to illustrate:
public static void myMethod(List<? extends Comparable> struttura) {}
public static void main(String[] args) {
List<Integer> lista = null;
myMethod(lista); // compiles OK
}