【发布时间】:2019-09-05 03:42:49
【问题描述】:
我应该得到以下错误:
class.dart:11:11:错误:没有为类“Y”定义吸气剂“_privateID”。 - “Y”来自“class.dart”。 尝试将名称更正为现有 getter 的名称,或定义名为“_privateID”的 getter 或字段。
来自以下代码?
mixin.dart:
class Mixin {
static int _nextID = 0;
int publicID = _nextID++; // I only need one of these lines
int _privateID = _nextID++; // but this variable is inaccessible
}
class.dart:
import 'mixin.dart';
class X with Mixin {
void run() {
print(publicID); // no error here
}
}
class Y with Mixin {
void run() {
print(_privateID); // Error: _privateID not defined
}
}
void main() {
Y().run();
}
或者这是一个错误?如果不是错误,我想了解为什么这种行为是合理的。
当我在与上述类相同的文件中定义 mixin 时,我没有收到任何错误。
(Dart SDK 2.4.1.)
【问题讨论】: