groovy
  1. groovy
  2. GROOVY-4947

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

    Details

    • Type: Improvement Improvement
    • Status: Closed 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
    • Patch Submitted:
      Yes
    • Number of attachments :
      1

      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

        There are no comments yet on this issue.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: