Last active
January 24, 2023 17:35
-
-
Save osa1/c6165e4a08eff358ab45f449d64d35fc to your computer and use it in GitHub Desktop.
Strange Dart 8
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 { | |
@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