Skip to content

Instantly share code, notes, and snippets.

@timsneath
Created June 3, 2022 01:29
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 timsneath/d74891618edcb1725f37f8779c87edbb to your computer and use it in GitHub Desktop.
Save timsneath/d74891618edcb1725f37f8779c87edbb to your computer and use it in GitHub Desktop.
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