Lars Heuer | 25 Jul 16:28
Favicon

jarray and Arrays.equals

Hi,

I've two ByteArrayOutputStreams which I convert into byte arrays. I
like to compare them via Arrays.equals. But Arrays.equals delivers the
wrong result. Simple example::

      >>> from java.util import Arrays
      >>> import jarray
      >>> a1 = jarray.array([1,2,3], 'b')
      >>> a2 = jarray.array([1,2,3], 'b')
      >>> Arrays.equals(a1, a1)
      True
      >>> Arrays.equals(a1, a2)
      False
      >>> Arrays.equals(a2, a2)
      True
      >>>

The expected result for Arrays.equals(a1, a2) is True.

Is that a bug?

Best regards,
Lars
--

-- 
Semagia 
<http://www.semagia.com>

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
(Continue reading)

Jeff Emanuel | 25 Jul 17:38
Favicon

Re: jarray and Arrays.equals


I expect this is another example jython
method invocation discrepancy.  Jython is
probably calling java.lang.Object.equals
(inherited by Arrays) with a1 as the object
and a2 as the argument.  You can invoke
the equals method that you want using
reflection:

  >>> byteArrayType=java.lang.Class.forName('[B')
  >>> 
byteArraysEquals=Arrays.getDeclaredMethod('equals',[byteArrayType,byteArrayType])
  >>> byteArraysEquals.invoke(None,[a1,a2])
  1
  >>>

Or more simply, == does what you want:

  >>> a1==a2
  1
  >>>

Lars Heuer wrote:
> Hi,
>
> I've two ByteArrayOutputStreams which I convert into byte arrays. I
> like to compare them via Arrays.equals. But Arrays.equals delivers the
> wrong result. Simple example::
>
>       >>> from java.util import Arrays
(Continue reading)


Gmane