Dlean Jeans
Dlean Jeans

Reputation: 986

In Haxe, how to create an object of template class T and assign properties to it

I want to do these in a util class for all classes which have position and size

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
       …
   }

}

Upvotes: 1

Views: 154

Answers (1)

Justo Delgado
Justo Delgado

Reputation: 544

I recommend you to read the 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.

Upvotes: 2

Related Questions