ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
给定一组多种类型,一个通用基本类型是一个类型,组中的所有类型可以统一为: > Given a set of multiple types,a common base type is a type which all types of the set unify against: ~~~ class Base { public function new() { } } class Child1 extends Base { } class Child2 extends Base { } class Main { static public function main() { var a = [new Child1(), new Child2()]; $type(a); // Array<Base> } } ~~~ 虽然Base没有被提到,Haxe编译器可以推断它为通用类型 Chid1 和 Child2 。Haxe编译器使用这类的合一在如下的情况: * 数组声明 * if/else * switch的case > Although Base is not mentioned, the Haxe Compiler manages to infer it as the common type of Child1 and Child2. The Haxe Compiler employs this kind of unification in the following situations: > * array declarations > * if/else > * cases of a switch