Skip to content

Instantly share code, notes, and snippets.

@tbrosman
Last active August 29, 2015 14:26
Show Gist options
  • Save tbrosman/d9997c2dc6951cea3c3f to your computer and use it in GitHub Desktop.
Save tbrosman/d9997c2dc6951cea3c3f to your computer and use it in GitHub Desktop.
Version: Haxe 3.2.0 release. Desc: In JS, Haxe essentially reifies the type for generic functions and the following code will work without issue and output "1" three times.
class Holder
{
public var components = new Array<Dynamic>();
public function new() {}
public function getFirst<T>():T
{
return cast components[0];
}
}
class Test {
static function main() {
var holder = new Holder();
holder.components.push(1);
var result:Int = holder.getFirst();
var result2:Dynamic = holder.getFirst();
var result3:Bool = holder.getFirst();
trace(result);
trace(result2);
trace(result3);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment