我想创建一个私有变量,但我做不到.
以下是我的代码:
void main() {
var b = new B();
b.testB();
}
class A {
int _private = 0;
testA() {
print('int value: $_private');
_private = 5;
}
}
class B extends A {
String _private;
testB() {
_private = 'Hello';
print('String value: $_private');
testA();
print('String value: $_private');
}
}
当我运行此代码时,我得到以下结果:
String value: Hello
int value: Hello
Breaking on exception: type 'int' is not a subtype of type 'String' of 'value'.
另外,在编辑此源代码时,我没有收到任何错误或警告.
如何在DART中创建私有变量?