class Main { static function main() { var comp = new AComponent([1, 2, 3]); trace(comp.doSomething()); } } interface Component { function doSomething():T; } @:forward @:multiType abstract AComponent(Component) { public function new(value:T); @:to public static inline function toInt(t:Component, value:Int):IntComponent { return new IntComponent(value); } @:to public static inline function toIntArray(t:Component>, value:Array):ArrayComponent { return new ArrayComponent(value); } } @:generic @:remove class ArrayComponent implements Component> { final value:Array; public function new(value:Array) { this.value = value; var x = []; for (i in 0...value.length) { var y = new AComponent(this.value[i]).doSomething(); x.push(y); } } public function doSomething():Array { return this.value; } } class IntComponent implements Component { final value:Int; public function new(value:Int) { this.value = value; } public function doSomething():Int { return value; } }