I'm writing a utility function in Haxe that adds some information to an exception before it gets thrown, and I'm having an issue with this in Java because the type parameters aren't being written out to the java function.
I've got a function defined in haxe like this :
public static function ex<T:java.lang.Exception>(exClass:Class<T>, msg:String):T
{
return Type.createInstance(exClass, [msg == null ? "" : msg]);
}
When this is compiled with the Java target, the java code that gets written looks like this:
If I then try to use this function from java:
throw ex(IllegalArgumentException.class, "test");
I get a compile error that "Object cannot be converted to Throwable". I believe this is because the type parameter is missing from the exClass parameter, so the java compiler just sets the return type to Object. If I add that type parameter to the exClass type:
I'm writing a utility function in Haxe that adds some information to an exception before it gets thrown, and I'm having an issue with this in Java because the type parameters aren't being written out to the java function.
I've got a function defined in haxe like this :
When this is compiled with the Java target, the java code that gets written looks like this:
If I then try to use this function from java:
throw ex(IllegalArgumentException.class, "test");
I get a compile error that "Object cannot be converted to Throwable". I believe this is because the type parameter is missing from the exClass parameter, so the java compiler just sets the return type to Object. If I add that type parameter to the exClass type:With this change the function compiles and works as expected. Any ideas if there is a workaround for this issue?