HHH-10052 - documentation about hashCode and equals not up to date
This commit is contained in:
parent
92dfd69937
commit
0834ab6b1d
|
@ -5,27 +5,20 @@ public class Person {
|
|||
@GeneratedValue
|
||||
private Integer id;
|
||||
|
||||
...
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return id != null ? id.hashCode() : 0;
|
||||
return Objects.hash( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals() {
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( !( o instanceof Person ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ( id == null ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Person other = ( Person ) o;
|
||||
return id.equals( other.id );
|
||||
Person person = (Person) o;
|
||||
return Objects.equals( id, person.id );
|
||||
}
|
||||
}
|
|
@ -9,35 +9,28 @@ public class Person {
|
|||
private String ssn;
|
||||
|
||||
protected Person() {
|
||||
// ctor for ORM
|
||||
// Constructor for ORM
|
||||
}
|
||||
|
||||
public Person( String ssn ) {
|
||||
// ctor for app
|
||||
// Constructor for app
|
||||
this.ssn = ssn;
|
||||
}
|
||||
|
||||
...
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
assert ssn != null;
|
||||
return ssn.hashCode();
|
||||
return Objects.hash( ssn );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals() {
|
||||
public boolean equals(Object o) {
|
||||
if ( this == o ) {
|
||||
return true;
|
||||
}
|
||||
if ( !( o instanceof Person ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final Person other = ( Person ) o;
|
||||
assert ssn != null;
|
||||
assert other.ssn != null;
|
||||
|
||||
return ssn.equals( other.ssn );
|
||||
Person person = (Person) o;
|
||||
return Objects.equals( ssn, person.ssn );
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue