The Equals method of object class in Java __java

Source: Internet
Author: User

All classes inherit the Equals method from the object class

The Equals method source code in the object class is as follows:

public boolean equals (Object obj)
{return this
	= = obj;
}

The Equals method in object directly determines whether the value of this and obj itself is equal, which is used to determine whether the object that calls equals and the object referenced by the parameter obj are the same object, and the same object refers to the same storage unit in memory. Returns true if this and obj point to the same memory object for Hi, if this and obj point to the same block of memory, return false, noting that even two different memory objects with exactly the same content are returned false.

If it is the same memory, the Equals method in object returns True and, if it is different memory, returns false

If you want two objects of different memory but the same content to return True when they are equals, we need to rewrite the equal method of the parent class

The string class has overridden the Equals method in Object

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.