Im trying to understand the following code.
class Test<E extends SubTest>
{
List<Vector<E>> links;
Test()
{
links = MyStaticClass.aList;
// Where aList is static ArrayList<Vector<SubTest>>;
}
}
How come assigning the following ArrayList to links List gives an error. Souldnt it understand the assignment considering i extended E with SubTest.
When I have a parameter T t; i can access t properties, but i cant do the said assing. Wouldnt List<Vector<T>> links expect to get ArrayList<Vector<SubTest>> anyway ?
You’re misunderstanding the error.
The actual problem is that
Eis not the same asSubTest.If you make an instance of
Test<SubSubTest>(whereSubSubTestinheritsSubTest), your code would try to put a collection ofSubTests (which can hold any derived class) into a variable of typeList<Vector<SubSubTest>>(which can only holdSubSubTest).