Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-1549

Array equality is not treated same as List equality

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.0-JSR-6
    • 1.1-rc-1
    • groovy-jdk
    • 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".

      Attachments

        Activity

          People

            paulk Paul King
            marc@anyware.co.uk Marc Palmer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: