dart 库和可见性
示例
与Java,飞镖不具备关键字public,protected和私有。如果标识符以下划线开头_,则它是其库的私有标识符。
例如,如果您在单独的库文件(例如other.dart)中拥有类A,则:
library other;
class A {
int _private = 0;
testA() {
print('int value: $_private'); //0
_private = 5;
print('int value: $_private'); //5
}
}然后将其导入您的主应用程序,例如:
import 'other.dart';
void main() {
var b = new B();
b.testB();
}
class B extends A {
String _private;
testB() {
_private = 'Hello';
print('String value: $_private'); //你好
testA();
print('String value: $_private'); //你好
}
}您将获得预期的输出:
String value: Hello int value: 0 int value: 5 String value: Hello
热门推荐
10 小学毕业父母简短祝福语
11 幼儿生日祝福语模板简短
12 新娘妈妈的祝福语简短
13 邻居聚会祝福语大全简短
14 十条祝福语简短
15 给同学祝福语的简短
16 过年祝福语简短祝妈妈
17 祝女儿简短祝福语大全
18 恩师诗词祝福语简短大全