Skip to content

Instantly share code, notes, and snippets.

@rhalff
Last active June 20, 2021 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rhalff/ba1db771653df43dc68161bd129837b6 to your computer and use it in GitHub Desktop.
Save rhalff/ba1db771653df43dc68161bd129837b6 to your computer and use it in GitHub Desktop.
Generics oddness
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