Created with <3 with dartpad.dev.
Last active
August 11, 2022 12:46
-
-
Save Quingsley/8f5d7fd5d658eabfcd43b8054732a601 to your computer and use it in GitHub Desktop.
Dart-Generics
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
void main() { | |
var listEx = <int>[]; | |
listEx.add(341); | |
listEx.add(1); | |
listEx.add(23); | |
// iterating across list listEx | |
for (int element in listEx) { | |
print(element); | |
} | |
var circleSlot = Slot<Circle>(); | |
circleSlot.insert(Circle()); | |
} | |
class Circle{ | |
String shape = '⭕'; | |
} | |
class Square{ | |
String shape = '🟥'; | |
} | |
class Slot<T>{ | |
String shape = ''; | |
insert(T shape){ | |
print('I am $shape'); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment