在Haxe中,如何创建模板class T的对象并为其分配属性
In Haxe, how to create an object of template class T and assign properties to it
我想在 util class 中为所有具有位置和大小
的 class 执行这些操作
class Creator<T> {
public function create() {
…
var object = new T(); // compile error: T is a compile time class or something (?)
object.x = x_; // compile error: T doesn't have an x properties
…
}
}
我建议你阅读 Haxe manual. The part you are interested on is how Haxe manages the Type parameters here and how to apply Constraints to them here. Once you have read that, the way you can achieve it is similar to this.
我想在 util class 中为所有具有位置和大小
的 class 执行这些操作class Creator<T> {
public function create() {
…
var object = new T(); // compile error: T is a compile time class or something (?)
object.x = x_; // compile error: T doesn't have an x properties
…
}
}
我建议你阅读 Haxe manual. The part you are interested on is how Haxe manages the Type parameters here and how to apply Constraints to them here. Once you have read that, the way you can achieve it is similar to this.