haxe
haxe copied to clipboard
[jvm] using generic functions
So im prototype working with FHIR in haxe, and would hopefully be able to generate libs from haxe that could be used in other languages (js / java initially), however, i hit a stumbling block. Im not 100% sure if its a bug or if its my usage, but, here goes:
@:expose
class TestObject {
public function new() {
}
public function testSomething<T>(clz:Class<Resource>):T {
var t:T = cast Type.createInstance(clz, []);
return t;
}
}
Then in java, ive tried to do the following:
TestObject t = new TestObject();
Patient p = t.testSomething(Patient.class);
However, it tells me:
Main.java:16: error: method testSomething in class TestObject cannot be applied to given types;
Patient p = t.testSomething(Patient.class);
^
required: Class<Object>
found: Class<Patient>
reason: cannot infer type-variable(s) T
(argument mismatch; Class<Patient> cannot be converted to Class<Object>)
where T is a type-variable:
T extends Object declared in method <T>testSomething(Class<Object>)
1 error
Digging around a little i think its because, the testSomething
function signature (in java) is:
public <T> T testSomething(java.lang.Class<java.lang.Object> clz)
And following the Patient
class through it ends up as (again, in java):
Patient -> DomainResource -> Resource -> haxe.jvm.Object
and im assuming haxe.jvm.Object
is incompatible with java.lang.Object
?
Any thoughts on how to achieve this?
Thanks in advance, Ian