Last active
May 4, 2021 23:59
-
-
Save timsneath/d9f817d0aaacd5069ded5d469261e494 to your computer and use it in GitHub Desktop.
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
abstract class BaseObject { | |
final String species; | |
BaseObject(this.species); | |
} | |
class Rabbit extends BaseObject { | |
Rabbit(String species) : super(species); | |
} | |
class Orange extends BaseObject { | |
Orange(String species) : super(species); | |
} | |
T doMagicPerformance<T extends BaseObject>(BaseObject object) { | |
// Hide orange in hat | |
final hiddenObject = object.species; | |
// Do magic | |
for (var i = 0; i <= 10; i++) { | |
print('Abracadabra'[i]); | |
} | |
final newObject = T(hiddenObject.species); | |
// Abracadabra! | |
return newObject; | |
} | |
void main() { | |
Orange orange = Orange('Citrus sinesis'); | |
Rabbit rabbit = doMagicPerformance<Rabbit>(orange); | |
print(rabbit.species); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment