Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 462484

Summary: [hashcode/equals] improve code style of generated equals and hashCode methods
Product: [Eclipse Project] JDT Reporter: Franz van Betteraey <fvbetteraey>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: CLOSED DUPLICATE QA Contact:
Severity: enhancement    
Priority: P3 CC: noopur_gupta
Version: 4.4.2   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Franz van Betteraey CLA 2015-03-18 12:37:34 EDT
Eclipse offers the ability to generate equals and hashCode methods. The generated code is verbose and could be more compact and readable since the introduction of the "Objetcs" class in Java 7 (http://docs.oracle.com/javase/7/docs/api/java/util/Objects.html).

Example:

package foobar;

import java.util.Objects;

public class FooBar {

  public int foo;
  public String bar;

  @Override
  public boolean equals(Object obj) {
    if (this == obj) {
      return true;
    }
    if (obj == null || getClass() != obj.getClass()) {
      return false;
    }
    FooBar other = (FooBar) obj;
    return Objects.equals(foo, other.foo) && Objects.equals(bar, other.bar);
  }

  @Override
  public int hashCode() {
    return Objects.hash(foo, bar);
  }

}

As this code only works since Java 7 it would be nice if the code style could be selectable.
Comment 1 Noopur Gupta CLA 2016-06-13 04:43:04 EDT

*** This bug has been marked as a duplicate of bug 424214 ***