octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Auto-boxing Java numerical values


From: Michael Goffioul
Subject: Re: Auto-boxing Java numerical values
Date: Fri, 21 Dec 2012 11:52:40 -0500

On Thu, Dec 20, 2012 at 11:45 PM, Rik <address@hidden> wrote:
On 12/20/2012 02:28 PM, address@hidden wrote:
> Message: 1
> Date: Thu, 20 Dec 2012 13:38:18 -0800 (PST)
> From: Philip Nienhuis <address@hidden>
> To: address@hidden
> Subject: Auto-boxing Java numerical values (cs 15820:00172e5c2302)
> Message-ID: <address@hidden>
> Content-Type: text/plain; charset=us-ascii
>
> Rik,
>
> I saw you've extended 'autoboxing' of Java doubles into Octave doubles to
> Java short/long/float etc.
> Isn't there a risk that this will definitely break code unavoidably
> depending on the old behavior?
>
> Example:
> In the io package there's code invoking LibreOffice (behind the scenes)
> through a UNO-Java bridge. Somewhere in that code LibreOffice (i.e., a UNO
> Java method) expects a Java short value or object. If Octave casts that
> java.lang.Short object into a double, how can that short value be conveyed
> to Java? AFAICS there's no way to typecast Octave values into Java class
> types. Or can we now do:
>
>   <SomeOctaveDouble>.shortValue()
>
> ? (i.e., applying Java methods to amenable Octave classes)
>
> AFAICS Matlab simply doesn't do any, or very limited, 'autoboxing'.
The documentation,
http://www.mathworks.com/help/matlab/matlab_external/handling-data-returned-from-a-java-method.html,
has a table showing how each Java return type is converted to a Matlab
type.  For all numeric scalar values Matlab chooses double which is what
the changeset in question does.

Again, this is worth verifying in case actual behavior does not match the
documentation.  What does the following return?

x = javaObject ('java.lang.Double', 4.2);
y = x.shortValue;
class (y)

I think the real issue is with the unbox routine.  When you call a Java
method Octave invokes unbox() to convert its native type to a corresponding
Java type.  In the case you mention, Octave should look at the method
signature and see that the UNO method wants a short and do that
conversion.  Unfortunately, the unbox code does nothing of the sort and is
looking at the Octave class to try and guess what the appropriate Java
class would be.  This is just one of the issues needing attention with Java.

That part is actually in ClassHelper.java, method (findMethod, isCallableFrom, castArguments...).

Michael.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]