How to implement hashCode and equals method

前端 未结 6 847
无人共我
无人共我 2020-12-01 12:08

How should I implement hashCode() and equals() for the following class in Java?

class Emp 
{
  int empid ; // unique across all the         


        
6条回答
  •  余生分开走
    2020-12-01 12:42

    If code is unique (i.e. your business key), it's best to only use the code for equals and hashCode - it's good practice to seperate business key (code) from object id (id).

    Here's a nice read: Hibernate Documentation: Equals and HashCode (valid not only for Hibernate itself)

提交回复
热议问题