DaveAKing / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Should Objects.equal handle arrays with Arrays.equals? #1425

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I was recently bitten by a bug concerning calling Objects.equal passing arrays 
(the primitive type e.g. int[]) as parameters.

The documented behavior of Objects.equal states that it would be the same 
behavior as calling array1.equals(array2). Those in turn are equivalent of 
calling array1 == array2.

I wonder if Objects.equal could step in and provide a uniform semantic in this 
case. If not, I'm curious to learn the rationale behind it.

Original issue reported on code.google.com by thiago.a...@gmail.com on 23 May 2013 at 6:19

GoogleCodeExporter commented 9 years ago
The behavior you seek is provided by java.util.Arrays.deepEquals(), which is 
more self-documenting when you use it.

We didn't to confuse the issue of exactly what Objects.equal() is for.  The 
broader lesson here is to avoid arrays as much as possible, especially Object 
arrays, which have virtually no discernible advantages over lists anymore.

Original comment by kevinb@google.com on 24 May 2013 at 2:27

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<issue id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:12

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:08