名字" Word"不是一个类/类型

时间:2014-06-15 19:05:34

标签: list class dart

我在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

我相信我编写的Word类类似于Bit类,并且在使用Word时在Table中使用时不会抛出错误。我错过了什么吗?

1 个答案:

答案 0 :(得分:3)

您在Table类中使用Word作为构造函数。

Word(List<List> words) {
  words.forEach((word) => _words.add(new Word(word)));
}

你的构造函数应该是Table的外观。

Table(List<List> words) {
  words.forEach((word) => _words.add(new Word(word)));
}