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 E is not the same as SubTest.
If you make an instance of Test<SubSubTest> (where SubSubTest inherits SubTest), your code would try to put a collection of SubTests (which can hold any derived class) into a variable of type List<Vector<SubSubTest>> (which can only hold SubSubTest).
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