How to override equals method in Java

后端 未结 9 1569
自闭症患者
自闭症患者 2020-11-22 01:41

I am trying to override equals method in Java. I have a class People which basically has 2 data fields name and age. Now I want to ove

9条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 01:59

    if age is int you should use == if it is Integer object then you can use equals(). You also need to implement hashcode method if you override equals. Details of the contract is available in the javadoc of Object and also at various pages in web.

提交回复
热议问题