Is the below is correct equals and hashCode implementation in Java? -


when object's value equal need return true.

example

@override public int hashcode() { return new hashcodebuilder().append(value).tohashcode(); }  @override public boolean equals(final object obj) { if (obj instanceof numbervalto) {   final numbervalto other = (numberval) obj;   return new equalsbuilder().append(value, other.getvalue()).isequals(); } return false; } 

is above fine or wrong?

i saw in few applications hashcode being multiple each , every field of table , not sure whether correct approach.

assume entity has 4 columns assume entity has 2 columns

  1. which best approach generate same?
  2. also, need implement hashcode() , equals() hibernate entity class?

thanks.

yes it's fine, assuming apache commons helper classes you're using. @vino correct point out adding if (obj == this) return true; start of equals method can worthwhile optimisation, methods correct is.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -