<分区>
我在讨论全局状态的 flutter 教程中有以下代码:
static GlobalState instance = new GlobalState._();
GlobalState._();
._ 到底在做什么?这在技术上只是一个空白方法吗?
<分区>
我在讨论全局状态的 flutter 教程中有以下代码:
static GlobalState instance = new GlobalState._();
GlobalState._();
._ 到底在做什么?这在技术上只是一个空白方法吗?
最佳答案
这是一个私有(private)构造函数。此模式用于防止客户端实例化或子类化 GlobalState
,因此程序中唯一可用的 GlobalState
实例是 instance
。
关于dart - flutter/dart 中的 '._' 约定是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52193352/