Uploaded image for project: 'NetBeans'
  1. NetBeans
  2. NETBEANS-415

Revisit hashCode(), equals() implementation

    Details

    • Type: Improvement
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      (CCing as many people from the original discussion as I could find: Svata Dedic Niklas Matthies Jan Lahoda)

      Given that Netbeans now requires JDK 7, consider having the code generator delegate to

      Objects.hashCode(Object) and Objects.hash(Object...) as they result in cleaner code than what is currently being generated.

      As for equals(), the implementation generated by Netbeans violates the Java specification of java.lang.Object and should be fixed right away. You can read a more detailed discussion at https://netbeans.org/bugzilla/show_bug.cgi?id=156994 [1] but essentially we agreed to fix this with a flag in the Options dialog to let users decide which approach they prefer.

      [1] In my last post I suggested:

      1. Making "instanceof" the default.
      2. Warning if a class uses "instanceof" and subclasses override equals/hashCode.
      3. Allowing users to configure whether they prefer instanceof or getClass()-based implementations of equals/hashcode on a project-level.
      4. Warning if a class uses "getClass()" and has any subclasses.
      5. Warnings should appear on the subclasses, not the parent class.

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              cowwoc Gili
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: