HaxeFoundation / hxjava

Haxe Java support library. Build scripts and support code.
The Unlicense
46 stars 14 forks source link

ClassCastException: java.lang.Integer cannot be cast to haxe.lang.Function #19

Closed sebthom closed 8 years ago

sebthom commented 8 years ago

The following code runs in other targets (tested on Neko, Python, JS), but fails on the Java target.

package test;

class MyTest {

    @:keep
    public static function testFunction() {
        trace("Hello World!");
    }

    @:keep
    public static var testField = 0;

    public static function main() {
        for (fieldName in Reflect.fields(MyTest))  {
            if(StringTools.startsWith(fieldName, "test")) {
                var theFunc = Reflect.field(MyTest, fieldName);
                if (Reflect.isFunction(theFunc)) {
                    theFunc();
                }            
            }
        }
    }

}

The following exepction is thrown:

Exception in thread "main" java.lang.ClassCastException: java.lang.Integer cannot be cast to haxe.lang.Function
waneck commented 8 years ago

Try typing theFunc specifically as Dynamic. It is being inferred as a function and thus fails on typed targets