【发布时间】:2015-06-14 15:48:11
【问题描述】:
我有一个扩展 Iterable 的接口(以及其他接口)。
interface MyInterface extends Iterable {
public function iterator ():Iterator<Dynamic>;
}
这给了我
MyInterface.hx:1:第 1-3 行:类型参数的数量无效 可迭代
正确的方法是什么?
【问题讨论】:
我有一个扩展 Iterable 的接口(以及其他接口)。
interface MyInterface extends Iterable {
public function iterator ():Iterator<Dynamic>;
}
这给了我
MyInterface.hx:1:第 1-3 行:类型参数的数量无效 可迭代
正确的方法是什么?
【问题讨论】:
Iterable 被定义为typedef,而不是interface,所以这行不通。
只需在您的类中添加一个名为iterator() 的函数就可以了,无需实现或扩展任何东西。这种机制称为structural subtyping。
有更多关于迭代器的信息here。
【讨论】: