class Test {
static function main() {
trace("Passing an Array<Int>: " + add([10, 20, 30]));
trace("Passing an Int: " + add(3));
// This shouldn't be possible!!!
trace("Passing an Array<String>: " + add(["a", "b", "c"]));
trace("Passing a String: " + add("hello"));
}
static function add(o:Dynamic):Array<Int> {
var a:Array<Int>;
if(Std.is(o, Array)) {
a = cast o;
} else if(Std.is(o, Int)) {
a = [for(i in 0...Std.int(o)) i];
} else {
throw "The value isn't an Array or an Int";
}
a.push(100);
a.push(300);
return a;
}
}