java object reference to the object, the content is equal, equal to address the problem

First, read a blogger's article is about the equivalent of java object problem, come and discover the bloggers on this issue directly reproduced:

       Article blog address: https://blog.csdn.net/yjclsx/article/details/80830324

 

Second, for a java object, we should know a few points:

  1, the object: the object is no name, for example; Person per = new Person (), pay attention, here's Person is not an object name, you can think about, if this is the object name, then, Person per1 = new Person after () finished, the object name is Person? Obviously not, Person here is just a class template, which allows us to create an unlimited number of objects, but these objects do not have names, we can not directly access, only indirect access to an object by creating an object reference.

  2, object reference: the above is what we call per object reference, Person per = new Person () is actually divided into two steps:

       (1) Person per, create an object reference.

    (2) per = new Person (), new Person () statement object is created, an assignment refers to: Object reference point to the object created.

  3, the object address: java java heap objects are present, each new one is equivalent to the newly created object (the unique address assigned a storage object, but the object reference is stored in a java heap). Because between references and references also possible assignment -> represents the two object references point to the same object.

  4, Object content: for example, to create the basic data types: Integer a = new Integer (5); content object is 5, if there are two object references point to the same object, which object reference to the contents of the object made changes operation, then another object reference to the contents of the object pointed to is the same, which is equivalent to two people eat the same dish, one clip away some, then other people see the same clip is take some of that dish up.

Once you know the concept of the above, it is easy to understand the difference between the following to say:

  (1) equals object in (): used to determine whether two objects are equal (the same whether it is a reference to an object) / two content objects are equal, and not to the address in the heap memory.

  (2) "==": for comparison when compared to the basic data type is a value for comparing the comparison reference type is a reference point address.

 

Guess you like

Origin www.cnblogs.com/yangrongkuan/p/12571475.html