ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
>[warning] 定义:结构子类型化 结构子类型化定义了一个在拥有同样结构的类型之间的隐式的关系。 >[warning] Definition: Structural Subtyping Structural subtyping defines an implicit relation between types that have the same structure. Haxe中的结构自类型化在合一时被许可: * 一个类(第2.3节)带有一个结构(第2.5节),和 * 一个结构带有另外一个结构 > Structural sub-typing in Haxe is allowed when unifying > * a class (2.3) with a structure (2.5) and > * a structure with another structure. 后面的例子是Haxe标准库中Lambda类的一部分: > The following example is part of the Lambda class of the Haxe Standard Library : ~~~ public static function empty<T>(it : Iterable<T>):Bool { return !it.iterator().hasNext(); } ~~~ 空方法检查一个Iterable是否有一个元素。为了这个目的,没有必要了解任何的参数类型除了事实上它被认为是一个迭代。这允许调用 空方法使用任何统一Iterable<T>的类型,这应用到Haxe标准库中的很多类型。 > The empty-method checks if an Iterable has an element. For this purpose, it is not necessary to know anything about the argument type other than the fact that it is considered an iterable. This allows calling the empty-method with any type that unifies with Iterable<T> which applies to a lot of types in the Haxe Standard Library. 这种类型化可以非常方便,但是大量使用可能影响静态目标语言的性能,在性能影响(第2.5.4节)部分有介绍。 > This kind of typing can be very convenient but extensive use may be detrimental to performance on static targets, which is detailed in Impact on Performance (Section 2.5.4).