-
-
Save heftekharm/1f9438136fdb48a73a695d1615431de9 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
final _alreadyCreatedCircleInstances = Map<int, Circle>(); | |
class Circle { | |
final int size; | |
Circle._(this.size); | |
factory Circle(int size) { | |
_alreadyCreatedCircleInstances[size] = _alreadyCreatedCircleInstances[size] ?? Circle._(size); | |
return _alreadyCreatedCircleInstances[size]!; | |
} | |
} | |
void main(){ | |
var c1 = Circle(40); | |
var c2 = Circle(40); | |
print("${c1 == c2}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment