Hi,
Using java-1.2.6, I have a problem with passing a Boolean parameter to a Java
method.
It seems that octave logical type is translated into java.lang.Double, not
java.lang.Boolean.
At least in some cases.
Here is the method I want to call (from Weka 3.6.2):
public double[] evaluateModel(Classifier classifier,
Instances data,
java.lang.Object... forPredictionsPrinting)
throws java.lang.Exception
Calling
> java_invoke(o, "evaluateModel", c, d)
I get this error:
error: [java] java.lang.NoSuchMethodException: evaluateModel
So, I need to provide the optional parameter "forPredictionsPrinting".
If provided, forPredictionsPrinting needs to be a StringBuffer object, a
weka.core.Range object, and a boolean:
sf = java_new('java.lang.StringBuffer');
range = java_new('weka.core.Range','first-last');
jtrue = java_new('java.lang.Boolean', true);
Still,
> java_invoke(o, 'evaluateModel', c, d, sf,range,jtrue);
produces
error: [java] java.lang.NoSuchMethodException: evaluateModel
I need to put the optional parameters into a Java array:
jarray = java_new('java.lang.Object',3);
jarray(1) = sf;
jarray(2) = range;
jarray(3) = jtrue;
Calling
> java_invoke(o, 'evaluateModel', c, d, jarray)
I now get the following error:
error: [java] java.lang.ClassCastException: java.lang.Double cannot be
cast to java.lang.Boolean
In fact, evaluateModel casts forPredictionsPrinting[2] to
java.lang.Boolean, but the parameter has been converted into a
java.lang.Double.
With jarray(3) = logical(1), I get the same error.
The only solution I've found was to remove lines 762 to 770 in
__java__.cc:
if (retval.is_undefined ())
{
cls = jni_env->FindClass ("java/lang/Boolean");
if (jni_env->IsInstanceOf (jobj, cls))
{
jmethodID m = jni_env->GetMethodID (cls, "booleanValue",
"()Z");
retval = jni_env->CallBooleanMethod (jobj, m);
}
}
Doing this, jtrue remains a Java object instead of being converted into
an Octave double.
Like this, calling
> java_invoke(o, 'evaluateModel', c, d, jarray)
works fine.
Is there any possibility to solve this in a better way?
I think, octave logical type should always be converted into
java.lang.Boolean and vice versa.
Thanks,
Gerhard
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Octave-dev mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/octave-dev