Skip to content

Instantly share code, notes, and snippets.

@osa1
Last active January 24, 2023 17:35
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 osa1/c6165e4a08eff358ab45f449d64d35fc to your computer and use it in GitHub Desktop.
Save osa1/c6165e4a08eff358ab45f449d64d35fc to your computer and use it in GitHub Desktop.
Strange Dart 8
class A {
@override
Type get runtimeType => int;
}
class B<T> {}
void main() {
print(A().runtimeType); // int
print(B<A>().runtimeType); // B<A>
}
/*
It's actually not possible for the second print above to print `B<int>`,
because `runtimeType` is an instance method (not static), and `runtimeType`
implementation of `B` does not have a `T` instance to call `runtimeType`.
*/
class C<T> {
@override
Type get runtimeType => C<T>; // cannot call `runtimeType` of `T` here
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment