【问题标题】:Haxe Interface that extends Iterable扩展 Iterable 的 Haxe 接口
【发布时间】:2015-06-14 15:48:11
【问题描述】:

我有一个扩展 Iterable 的接口(以及其他接口)。

interface MyInterface extends Iterable {
  public function iterator ():Iterator<Dynamic>;
}

这给了我

MyInterface.hx:1:第 1-3 行:类型参数的数量无效 可迭代

正确的方法是什么?

【问题讨论】:

    标签: generics interface haxe


    【解决方案1】:

    Iterable 被定义为typedef,而不是interface,所以这行不通。

    只需在您的类中添加一个名为iterator() 的函数就可以了,无需实现或扩展任何东西。这种机制称为structural subtyping

    有更多关于迭代器的信息here

    【讨论】:

      猜你喜欢
      • 2014-05-06
      • 2015-08-09
      • 2020-09-07
      • 2017-03-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-22
      • 2023-04-08
      • 1970-01-01
      相关资源
      最近更新 更多