Skip to content

Instantly share code, notes, and snippets.

@timnew
Created May 4, 2021 03:53
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 timnew/5c77944590ace8a56cf991e54f44047a to your computer and use it in GitHub Desktop.
Save timnew/5c77944590ace8a56cf991e54f44047a to your computer and use it in GitHub Desktop.
Dart Generic Experiment
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