Skip to content

Instantly share code, notes, and snippets.

@Simn
Created August 2, 2013 08:32
Show Gist options
  • Save Simn/6138349 to your computer and use it in GitHub Desktop.
Save Simn/6138349 to your computer and use it in GitHub Desktop.
Haxe generic type parameter construction
typedef Constructible = {
public function new():Void;
}
@:generic
class Gen<T:(Constructible, Main)> {
public function new() { }
public function make() {
return new T();
}
}
class Main {
static public function main() {
new Gen<Main>().make();
new Gen<Mainer>().make();
new Gen<Mainest>().make();
}
public function new() {
trace("new Main");
}
}
class Mainer extends Main {
public function new() {
trace("new Mainer");
super();
}
}
class Mainest extends Mainer {
public function new() {
trace("new Mainest");
super();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment