I ran into the following problem:
class A {}
class B extends A {}
class C<T extends A> {
C() {
test(B()); // line 7
}
void test(T t) {}
}
Error: The argument type 'B' can't be assigned to the parameter type 'T' - line 7
I don't understand why type B can't be assigned to a parameter of type T because B clearly extends A and T is also defined to extend A? To fix this error I tried casting B to B:
test(B() as B);
Info: Unnecessary cast - line 7
The info makes sense to me but I don't understand why this cast fixes the error and this also works at runtime for me. The best solution without any errors or info I found was:
test(B() as T);
test(B() as B)
does not remove the assignment error for me. I instead get the warning about the unnecessary cast and the assignment error, which seems correct.