gpt4 book ai didi

class - 达特:我无法在另一个类(class)中实例化一个类(class)

转载 作者:行者123 更新时间:2023-12-03 02:53:54 27 4
gpt4 key购买 nike

我试图在Dart中扩展列表并在此列表中使用另一个类。

这是我的示例,其中注释出了问题:

import "Radio.dart"; // <= if i delete the Test class this import is unused for some reason
import "dart:collection";

class Test {
Radio radio = new Radio(1, null, null, null); // <= works as expected
}

class RadioList<Radio> extends ListBase<Radio> {
List<Radio> radioList = new List();

int get length => radioList.length;

void set length(int length) {
radioList.length = length;
}

void operator []=(int index, Radio value) {
radioList[index] = value;
}

Radio operator [](int index) => radioList[index];

Radio radio = new Radio(1, null, null, null); // <= Error: The name Radio is not a class
}

不幸的是,我不知道为什么会这样。

提前致谢。

最佳答案

class RadioList<Radio> extends ListBase<Radio> {
^^^^^

您将引入一个名为 Radio的类型参数,它使 Radio类黯然失色。
更改为

class RadioList extends ListBase<Radio> {

它会工作。

关于class - 达特:我无法在另一个类(class)中实例化一个类(class),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24117327/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com