Created
June 3, 2022 01:29
-
-
Save timsneath/d74891618edcb1725f37f8779c87edbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Animal { | |
void makeNoise(); | |
} | |
class Dog extends Animal { | |
@override | |
void makeNoise() => print('Woof'); | |
} | |
class Cat extends Animal { | |
@override | |
void makeNoise() => print('Meow'); | |
} | |
class UtilityClass { | |
void doStuff<T extends Animal>() { | |
print(T.toString()); | |
T.makeNoise(); | |
} | |
} | |
void main() { | |
final myClass = UtilityClass(); | |
myClass.doStuff<Dog>(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment