This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Re: Array equality?

No replies
odersky
Joined: 2008-07-29,
User offline. Last seen 45 weeks 6 days ago.

On Tue, Sep 29, 2009 at 3:11 PM, Miles Sabin wrote:
> On Tue, Sep 29, 2009 at 2:07 PM, martin odersky wrote:
>> On Tue, Sep 29, 2009 at 1:05 AM, Jorge Ortiz wrote:
>>> Even Java seems to admit they got equals/hashCode wrong for Arrays. Would it
>>> be possible to use java.util.Arrays.equals and ju.Arrays.hashCode (note
>>> plural Arrays) instead of the inherited equals/hashCode from Object?
>>>
>> No, unfortunately, because arrays might masquerade as objects. So we
>> could only do it with a run-time check, which would slow down all
>> calls to equals and hashCode.
>
> I appreciate that you've just gone through the process of eliminating
> a lot of harmful array boxing, but wouldn't it be possible to box
> arrays only when they're viewed at Any or AnyRef?
>
In short no. All of that was leaky, and the leaks can't be fixed.
Also, consider interop. We'd have to distinguish between an AnyRef
from Java (don't box) and an AnyRef coming from Scala.

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland