Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: 1.0-JSR-6
-
Fix Version/s: 1.1-rc-1
-
Component/s: groovy-jdk
-
Labels:None
-
Number of attachments :
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".
I have a patch for this which works for Object types but primitive arrays are stored by Groovy in their primitive form and I need to make the patch work with that before submitting.