Created
August 21, 2025 06:03
-
-
Save rena2019/b9d17d8b6dc2f940060d09a8dd9941cd to your computer and use it in GitHub Desktop.
Dart constructor tear-offs
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
class Person { | |
String name; | |
static int _instanceCount = 0; | |
Person(this.name) { | |
_instanceCount++; // Zähler erhöhen, wenn eine neue Instanz erstellt wird | |
} | |
static int get instanceCount => _instanceCount; // Getter für den Zähler | |
} | |
void main() { | |
var createPerson = Person.new; //Tear-Off des Konstruktors | |
var person1 = createPerson('Alice'); | |
var p = Person('zwei'); | |
createPerson('X'); | |
print("${person1.name}, instanceCount: ${Person.instanceCount}"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment