I have a question about generics. I’m posting the relevant parts of my code here. I appreciate if you can guide me if what I need is actually possible to achieve.
I’m using Constructible<Void->Void>
because down the road (inside Room.hx
) I need to instantiate the State
class.
// Main.hx
var room: Room<State> = client.join("state_handler");
// Client.hx
@:generic
public function join<T:Constructible<Void->Void>>(roomName: String, ?options: Map<String, Dynamic>): Room<T> {
return new Room<T>(roomName, options);
}
// Room.hx
@:generic
class Room<T:Constructible<Void->Void>> implements IRoom {
// ...
}
Here’s the error this throws me:
Source/Main.hx:24: characters 15-48 : io.colyseus.Room<Unknown<0>> should be io.colyseus.Room_State
Source/Main.hx:24: characters 3-48 : io.colyseus.Room<haxe.Constructible<Void -> Void>> should be io.colyseus.Room_State
I’m using Haxe 4.0.0-rc.2
Thanks in advance!