Last active
June 20, 2021 19:33
-
-
Save rhalff/ba1db771653df43dc68161bd129837b6 to your computer and use it in GitHub Desktop.
Generics oddness
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class A {} | |
class B extends A { | |
String b() { | |
return 'b'; | |
} | |
} | |
class C<T extends A> { | |
const C(this.c); | |
final T c; | |
String? someMethod() { | |
if (c is B) { | |
return c.b(); // Method b isn't defined for the type unknown. | |
} | |
} | |
String? someMethod2() { | |
final _c = c; | |
if (_c is B) { | |
return _c.b(); | |
} | |
} | |
} | |
void main() { | |
print(C<B>(B())); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment