Why are these == but not `equals()`?

后端 未结 8 1692
灰色年华
灰色年华 2020-12-01 07:58

I\'m a bit confused about the way Java treats == and equals() when it comes to int, Integer and other types of numbers.

8条回答
  •  被撕碎了的回忆
    2020-12-01 08:28

    I remember a good practice for overriding "equal(object obj)" is of first checking the type of the parameter passed in. So perhap this causes X.equals(Y) to be false. You might check the souce code to dig out the truth :)

提交回复
热议问题