Feature Overview
This feature generates equals
and hashCode
methods for the class.
This feature generates equals
and hashCode
methods for the class.
None
@identity
public class IdentityDemo {
private String name;
private Integer id;
private Boolean active;
}
public class IdentityDemo {
private String name;
private Integer id;
private Boolean active;
public Boolean equals(Object other) {
if(other instanceof IdentityDemo) {
IdentityDemo target = (IdentityDemo)other;
return this.name == target.name && this.id == target.id && this.active == target.active;
}
return false;
}
public Integer hashCode() {
Map data = new Map();
data.put('name', this.name);
data.put('id', this.id);
data.put('active', this.active);
return Sweet.generateHashCode(data);
}
}
@identity
only includes non-static fields.
Some variations are:
Example | Description |
---|---|
@identity | Generate all non-static fields |
@identity({ 'name', 'id' }) | Generate the given fields |
@identity(fields={ 'name', 'id' }) | Generate the given fields |
Contribute on Github! Edit this section.