NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
给定一组多种类型,一个通用基本类型是一个类型,组中的所有类型可以统一为: > 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