What exactly does comparing Integers with == do?

前端 未结 7 550
旧时难觅i
旧时难觅i 2020-12-10 04:22

EDIT: OK, OK, I misread. I\'m not comparing an int to an Integer. Duly noted.

My SCJP book says:

When == is used to compare a primitive to a

7条回答
  •  执笔经年
    2020-12-10 05:00

    You're not comparing a primitive to a wrapper. You're comparing two wrappers (reference types). == compares object identity, which returns false because they're different objects.

提交回复
热议问题