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

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

Attach filesAttach ScreenshotVotersWatch issueWatchersCreate sub-taskLinkCloneUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 2.1.4
    • 2.1.5, 2.2.0-beta-1
    • ast builder
    • None
    • 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

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

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

            Dates

              Created:
              Updated:
              Resolved:

              Slack

                Issue deployment