【发布时间】:2014-06-15 19:05:34
【问题描述】:
我在 Dart 中有三个类,如下所示:
位:
part of CB_Crypto;
class Bit {
bool _state = false,
_sympathetic = false;
int _alignment = 0;
Bit(List args) {
_state = args[0];
_sympathetic = args[1];
_alignment = args[2];
}
bool state() => _state;
bool not() => _state = !_state;
bool set(bool state) => _state = state;
bool isSympathetic() => _sympathetic;
operator &(Bit b) => state() && b.state();
operator |(Bit b) => state() || b.state();
}
单词:
part of CB_Crypto;
class Word {
List<Bit> _bits = [];
Word(List<List> bits) {
bits.forEach((bit) => _bits.add(new Bit(bit)));
}
bool not(int i) => _bits[i].not();
void notAll() => _bits.forEach((bit) => bit.not());
}
表:
part of CB_Crypto;
class Table {
List<Word> _words;
Word(List<List> words) {
words.forEach((word) => _words.add(new Word(word)));
}
}
这些都在不同的文件中,并且是同一个库的一部分。但是,我在 Table 类中收到来自 Dartium 的警告,要求我使用 Word 作为类型并尝试实例化 Word 对象:the name "Word" is not a (type/class) and cannot be used as a parametrized type。
我相信我编写了类似于 Bit 类的 Word 类,并且在使用 Word 时在 Table 中使用时不会引发错误。我错过了什么吗?
【问题讨论】:
-
您能否显示引发此错误的代码?
-
我想知道这是否有效:
Word(List<List> words) {- 为了更好地理解,您应该为我们输入(内部)列表。 -
您是否将每个部分的
part "file.dart"添加到您的库中? -
@Robert 引发错误的代码是 Table 类(列表定义和 forEach 循环。
-
@GünterZöchbauer 是的,我做到了。