in my Event class, it has a name variable as a String, and I want the name to be the unique identifier of an object. In implementing the hashCode() method, which way is recommended or right?
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
return result;
}
or
@Override
public int hashCode() {
return name != null ? name.hashCode() : 0;
}