【发布时间】:2021-01-19 05:00:39
【问题描述】:
我正在尝试编写一个示例程序来尝试使用 go2 中提出的 go generic 来实现数据结构。
作为其中的一部分,我想定义一个迭代器接口。我有以下代码:
package collection
type Iterator interface {
//ForEachRemaining Performs the given action for each remaining element until all elements have been processed or
//the action throws an error.
ForEachRemaining(action func[T any](T) error) error
//HasNext returns true if the iteration has more elements.
HasNext() bool
//Next returns the next element in the iteration.
Next() error
//Remove removes from the underlying collection the last element returned by this iterator (optional operation).
Remove() error
}
它一直给我以下错误
function type cannot have type parameters
有什么方法可以定义泛型接口
【问题讨论】: