I have this interface and classes:
interface I {
void method1();
}
class A implements I {
void method1(){
....
}
}
Assume I have this list: List<A> aslist filled with A items, and I have a variable of type List<I> vari=null;
I need ti do vari=aslist? How can I do it with the minimum convertions?
You can’t. A
List<Car>is not aList<Vehicle>. If it was, you could do the following:and it would thus completely break the type-safety of the collection.
What you can do is the following: