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

@EqualsAndHashCode override not working when used with @Immutable if @Immutable appears first

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.1.4
    • Fix Version/s: 2.1.5, 2.2.0-beta-1
    • Component/s: ast builder
    • Labels:
      None
    • Environment:
      Groovy Version: 2.1.4 JVM: 1.7.0_11 Vendor: Oracle Corporation OS: Linux

      Description

      I am using the @Immutable annotation and need to customize the @EqualsAndHashCode fields. If the @Immutable annotation appears first it doesn't work. However, if I place @EqualsAndHashCode first it works.

      @Canonical works correctly regardless of what order the annotations appear.

      import groovy.transform.*
      
      @EqualsAndHashCode(includes = ['id'])
      @Immutable
      class A {
          String id
          String name
      }
      
      @Immutable
      @EqualsAndHashCode(includes = ['id'])
      class B {
          String id
          String name
      }
      
      def a1 = new A('1', 'foo')
      def a2 = new A('1', 'foo2')
      
      assert a1.equals(a2)
      assert a2.equals(a1)
      
      def b1 = new B('1', 'foo')
      def b2 = new B('1', 'foo2')
      
      assert b1.equals(b2)  // fails
      assert b2.equals(b1)  // fails
      

        Attachments

          Activity

            People

            • Assignee:
              paulk Paul King
              Reporter:
              jwagenleitner John Wagenleitner
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: