I have static java methods which I add to javascript with this method:
public void addJavaMethod(Method method)
{
try
{
FunctionObject fo = new FunctionObject(method.getName(), method, m_scope);
FunctionObject.putProperty(m_scope, method.getName(), fo);
}
catch(Exception e)
{
e.printStackTrace();
}
}
I always use the object class for parameters in these methods because it otherwise comes up with errors, for example:
instead of
static void setSomeFloatValueHere(float value){}
I use:
static void setSomeFloatValueHere(Object value)
{//convert this object to a float}
With booleans I can do a direct cast:
static void setBoolean(Object b){someBooleanObject = (Boolean)b;}
But with int,float,long,double, etc, I cannot do this.
I receive an error:
org.mozilla.javascript.Undefined cannot be cast to java.lang.Integer
How can I get this to work with those types as well? and possibly other non primitive type objects?
Thanks
Your object is probably not an Integer, but rather Number which has an intValue()
You can check the actual type by using value.getClass().getName().