How is the == operator implemented in Java?

后端 未结 4 2005
無奈伤痛
無奈伤痛 2021-01-04 23:33

Specifically, in the case of object reference equality, what does the == operator do?

Does the comparison return true if the references evaluate to the same object a

4条回答
  •  执笔经年
    2021-01-05 00:07

    The == operator just compares the references.

    References in the JVM are just a standard object pointer. This works out to a single 32bit or 64bit integer value (depending on platform).

    When you compare two object references, you're really just comparing two 32bit or 64bit integers, and if they're the same, you'll equate to equal. The integer values are a location in memory.

提交回复
热议问题