Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3974

"equals" should only be used for methods that override "Object.equals(Object)"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Active
    • Resolution: Unresolved
    • Labels:
    • Message:
      Rename this method.
    • Highlighting:
      Hide

      equals

      Show
      equals
    • Default Severity:
      Major
    • Impact:
      Low
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      Java
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      5min
    • Analysis Scope:
      Main Sources, Test Sources

      Description

      "equals" has a special place as a method name: it is expected to override boolean Object.equals(Object). Using the name for a method with some other signature is a recipe for confusion.

      Noncompliant Code Example

      public void equals(MyObject o) {  // Noncompliant
        //...
      }
      
      public bool equals(MyObject left, MyObject right) {  // Noncompliant
        // ...
      }
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              Unassigned Unassigned
              Reporter:
              ann.campbell.2 Ann Campbell
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: