Last active
August 29, 2015 14:26
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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