Created
May 4, 2021 03:53
-
-
Save timnew/5c77944590ace8a56cf991e54f44047a to your computer and use it in GitHub Desktop.
Dart Generic Experiment
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 Beacon<T>{} | |
class ExtendBeacon extends Beacon<String> { | |
} | |
class MixinBeacon with Beacon<String>{ | |
} | |
class ChildMixinBeacon extends MixinBeacon{} | |
class ImplementBeacon implements Beacon<String>{} | |
class Grandpa {} | |
class Dad extends Grandpa{} | |
class Son extends Dad{} | |
void check<B>(dynamic value ){ | |
print("${value.runtimeType} is $B: ${value is B}"); | |
} | |
void main(){ | |
check<Beacon>(ExtendBeacon()); | |
check<Beacon<dynamic>>(ExtendBeacon()); | |
check<Beacon<String>>(ExtendBeacon()); | |
check<Beacon<Pattern>>(ExtendBeacon()); | |
check<Beacon<int>>(ExtendBeacon()); | |
check<Beacon<Null>>(ExtendBeacon()); | |
check<Beacon<Never>>(ExtendBeacon()); | |
check<Beacon<void>>(ExtendBeacon()); | |
check<Beacon<Object>>(ExtendBeacon()); | |
print(""); | |
check<Beacon<String>>(ChildMixinBeacon()); | |
print(""); | |
check<Beacon<String>>(MixinBeacon()); | |
check<Beacon<String>>(ImplementBeacon()); | |
print(""); | |
check<Beacon<Grandpa>>(Beacon<Dad>()); | |
check<Beacon<Son>>(Beacon<Dad>()); | |
print(""); | |
check<Beacon>(Beacon<Null>()); | |
check<Beacon<Object>>(Beacon<Null>()); | |
check<Beacon<void>>(Beacon<Null>()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment