我有两种编写构造器的方法。className()和className._()
className()
className._()
它们之间有什么区别,什么时候应该使用?
class GlobalState{ final Map<dynamic,dynamic> _data=<dynamic,dynamic>{}; static GlobalState instance = new GlobalState._(); GlobalState._(); } //In Main Class GlobalState _store=GlobalState.instance; and class GlobalState{ final Map<dynamic,dynamic> _data=<dynamic,dynamic>{}; static GlobalState instance = new GlobalState(); } //In Main Class GlobalState _store=GlobalState();
例如:
class MyClass { MyClass(); MyClass.named(); MyClass._private(); MyClass._(); }
上面的类有四个构造函数:
MyClass()
MyClass.named()
MyClass._private()
MyClass._()