object - Dart 的私有(private)成员被曝光

标签 object dart private

我不确定是否有问题,或者我是否错过了一些非常基本的东西。
但我能够访问类外的类的私有(private)构造函数、方法和成员。

class A {
  static final _a = 1;
}

void main() {
  print(A._a);
}
输出 :
1
Dart 版本:
Dart VM version: 2.8.4 (stable) (Unknown timestamp) on "linux_x64"
测试截图:
Screenshot of the test

最佳答案

从文档:

identifiers that start with an underscore (_) are visible only inside the library. Every Dart app is a library, even if it doesn’t use a library directive.


私有(private)意味着它在写入它的文件中可用,而其他文件无法访问。所以这不是真正的私有(private)。您可以阅读更多信息 here .

关于object - Dart 的私有(private)成员被曝光,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63100209/

相关文章:

Javascript - 获取函数(方法)的类所有者

javascript - 对象数组在 AngOninit 中显示未定义 5

firebase - 如何在 flutter 应用程序中禁用云消息传递?

python - Python 类中是否有 “private” 变量?

mysql - 将个人明文密码存储在私有(private) mysql 数据库中安全吗?

java - java中私有(private)变量的获取和设置

python - 作为对象输入 python 3

Javascript从存储在索引上的数组内的对象获取键

flutter - 使用 ... 运算符将列表添加到另一个列表有什么区别?

android - 尝试在Google map 上显示自定义标记时,BitmapDescriptor.fromBytes()不起作用