Groovy
  1. Groovy
  2. GROOVY-4947

Little improvement in code generated for equals() by @EqualsAndHashCode ast transformation

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 1.8.2, 1.9-beta-3
    • Component/s: None
    • Labels:
      None
    • Flags:
      Patch

      Description

      Currently, equals() generated by @EqualsAndHashCode looks like

      class C {
            String a, b
            boolean equals(Object other) {
                    ...
                    ...
                    if(!(other instanceof C)) {return false}
                    if(this.a != other.a) {...}
                    if(this.b != other.b) {...}
                    ...
            }
      }
      

      It access getters/fields of enclosing class using type Object, which is not ideal and creates a little issue for static analysis done by Groovy++.

      A slightly better implementation could be:

      class C {
            String a, b
            boolean equals(Object other) {
                    ...
                    ...
                    if(!(other instanceof C)) {return false}
                    C another = (C) other
                    if(this.a != another.a) {...}
                    if(this.b != another.b) {...}
                    ...
            }
      }
      

      The patch attach has been reviewed on the "dev" mailing list.

        Activity

        Roshan Dawrani created issue -
        Roshan Dawrani made changes -
        Field Original Value New Value
        Resolution Fixed [ 1 ]
        Status Open [ 1 ] Resolved [ 5 ]
        Paul King made changes -
        Fix Version/s 1.9-beta-3 [ 17494 ]
        Fix Version/s 1.8.2 [ 17495 ]
        Paul King made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Mark Thomas made changes -
        Project Import Sun Apr 05 13:32:57 UTC 2015 [ 1428240777691 ]
        Mark Thomas made changes -
        Workflow jira [ 12733873 ] Default workflow, editable Closed status [ 12745672 ]
        Mark Thomas made changes -
        Flags Patch [ 10430 ]
        Patch Submitted Yes [ 10763 ]
        Mark Thomas made changes -
        Project Import Mon Apr 06 02:11:23 UTC 2015 [ 1428286283443 ]
        Mark Thomas made changes -
        Workflow jira [ 12969891 ] Default workflow, editable Closed status [ 12977644 ]

          People

          • Assignee:
            Roshan Dawrani
            Reporter:
            Roshan Dawrani
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development