Processing object (2)-= and equals Method

Source: Internet
Author: User

* What is "= and equals ()"? =: 1. determine whether the basic type variables are equal; 2. determine whether the reference type points to an object; equals (): determines whether the value pointed to by the reference type variable is the same (String is the standard, but can be rewritten ); * How to use "= and equals ()"? String str1 = "Hello"; String str2 = "Hello"; // output falsestr1 = str2; // output truestr1.equals (str2 ); * Why we use "= and equals ()"? Here we will talk about equals (). This method is of the Object class and can be rewritten. The meaning of rewriting is that "you can define equal standards by yourself. How do you think it is equal, in extreme cases, if you rewrite this method and always return a true value, then how can the ratios be equal. * Others: correctly override the principles of the equals method: Self-inversion, symmetry, transmission, consistency, and false for any x. equals (null) that is not null.

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.