1

我使用 LuaJ,它包含一个库:luajava,它允许通过反射将一个类传递给 lua 环境。你知道怎么做吗?我注意到有一种方法可以传递编译类:

_G.get("load").call(LuaValue.valueOf(
            "sys = luajava.bindClass('java.lang.System')\n" +
                    "print ( sys:currentTimeMillis() )\n")).call(); 

未编译的类:*.java 怎么样?如何通过它?

4

1 回答 1

0

如果您需要通过 Reflection 调用类,则无需额外的第三方库即可执行此操作,例如

        //calling class via reflection
        Class cls = Class.forName("com.test.reflection.AppTest");
        Object obj = cls.newInstance();

        //call the printIt method
        Method method = cls.getDeclaredMethod("printIt", noparams);
        method.invoke(obj, null);

        //call the printItString method, pass a String param 
        method = cls.getDeclaredMethod("printItString", paramString);
        method.invoke(obj, new String("mkyong"));

        //call the printCounter method
        method = cls.getDeclaredMethod("printCounter", noparams);
        method.invoke(obj, null);
于 2013-11-18T08:27:30.623 回答