Reputation: 1113
I'm facing a problem converting dart 1.25 code to 2.7. My problem is with generic extends contraint.
With the older dart 1.25 version the generic type was understood to num when it wasn't specified.
void main() {
CustomType customType = new CustomType();// no T specified
}
class CustomType<T extends num> {
CustomType() {
print(T is num);//> why is this false ?
}
}
Why isn't the case ?
Upvotes: 0
Views: 85
Reputation: 25966
You used a wrong operator to compare classes. Use:
==
to compare 2 classes for equalityis
to check if an object is an instance of a class.void main() {
CustomType customType = new CustomType();// no T specified
}
class CustomType<T extends num> {
CustomType() {
print(T); // num
print(T == num); // true
print(1 is num); // true
}
}
Upvotes: 2