The code below produces a type error of:
"The argument type int can't be assigned to the parameter type num"
Why is sum
being considered a num
, when it's defined as int
?
If I change sum
from int
to var
, the error disappears.
Can someone explain why this is happening?
abstract class ISomeInterface {
void add<T>(T x);
}
class SomeClass implements ISomeInterface {
int sum;
@override
void add<int>(int x) {
sum = sum + x;
}
}