gpt4 book ai didi

dart - 如何在Dart中初始化一个空的LinkedList

转载 作者:行者123 更新时间:2023-12-03 03:08:49 25 4
gpt4 key购买 nike

我正在尝试在 Dart 中创建T类型的链接列表

var list = LinkedList<T>();

但是编辑说

'T' doesn't extend 'LinkedListEntry'. Try using a type that is or is a subclass of 'LinkedListEntry'.

最佳答案

基本用法示例:

import 'dart:collection';

void main() {
var list = LinkedList<MyEntry>();
list.add(MyEntry(1));
list.add(MyEntry(2));
list.add(MyEntry(3));
print(list);
print(list.last.previous);
list.last.previous.unlink();
print(list);
}

class MyEntry extends LinkedListEntry<MyEntry> {
final int id;
MyEntry(this.id);

@override
String toString() {
return '$id';
}
}

结果:

(1,2,3)
2
(1,3)

关于dart - 如何在Dart中初始化一个空的LinkedList <T>?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59375801/

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