"Song Hongkang Learning Diary 11" object class and Equals method

Source: Internet
Author: User

1 = =

(1) When the object is the basic data type, the comparison value;

(2) When the object is a reference type, the comparison is the address value!! 1

2 equals (): Only the reference data is processed; the Equals method in the object class still compares the address value!

But in the String,file,date class, the Equals method is overridden, and the value is compared;

3 String Class memory parsing

Person P1=new person ("floral", 20);

Person P2=new person ("Caocao", 40);

SYSO (P1==P2);//false

SYSO (P1.equals (p2));//false

Syso (P1.name.equals (P2.name));//equal! Because name is of type string, in a constant pool, the P1,P2 address values are not equal, but the p1.name and P2.name address values are equal.

Exception! is equal in string because it is overridden.

"Song Hongkang Learning Diary 11" object class and Equals method

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.