Luaj newInstance("java.lang.Byte") returns java.lang.Integer

160 views Asked by At

When using LuaJ, I was tring to call a java method that needs a Byte argument. But when I use luajava.newInstance("java.lang.Byte","2") It turned out to be a java.lang.Integer and caused an error.

java.lang.ClassCastException: class java.lang.Integer cannot be cast to class java.lang.Byte (java.lang.Integer and java.lang.Byte are in module java.base of loader 'bootstrap')

I can't modify the java method to do the cast. How can I get a Byte instance in lua?

Edit: The method is in minecraft sourcecode and I cant find the implementation. So I write a method to test.

java:

    public static String GetType(Object obj){
        return  obj.getClass().toString();
    }

lua:

print(MyJavaClass:GetType(luajava.newInstance("java.lang.Byte","2")))

And it is "class java.lang.Integer"

0

There are 0 answers