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 红包祝福语简短10字
18 周六早晨祝福语简短