Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
1.0-JSR-6
-
None
Description
There is no good reason why array equality should work differently from list equality:
groovy> def list1 = [1,2,3,4]
groovy> def list2 = [1,2,3,4]
groovy> assert list1 == list2
groovy> int[] arr1 = [1,2,3,4]
groovy> int[] arr2 = [1,2,3,4]
groovy> assert arr1 == arr2
Exception thrown: java.lang.AssertionError: Expression: (arr1 == arr2). Values: arr1 = [I@bc608f, arr2 = [I@677b56
Equality for lists compares the values, equality for arrays does identity. This seems very counter-intuitive, especially if you are writing code that does not mind whether it gets arrays or lists, and is not "Groovy".