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 Getter<T> {} | |
T get<T>(Getter<T> getter) { | |
if (T == int) { | |
return 42 as T; | |
} else if (T == String) { | |
return "the answer to life, the universe, and everything" as T; | |
} | |
throw "Unexpected type: ${T.toString()}"; |
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 Getter<T> {} | |
extension on Getter<int> { | |
int get() => 42; | |
} | |
extension on Getter<String> { | |
String get() => "the answer to life, the universe, and everything"; | |
} |
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
T create<T>(T Function(int) creator, int a) { | |
return creator(a); | |
} | |
class Bar { | |
int member; | |
Bar(this.member); | |
void doPrint() { print(member); } | |
} |
OlderNewer