In Java, integer i1= 0; Integer i2= 0; Why do you use the = = symbol?

Source: Internet
Author: User

In Java, integer i1= 0;  Integer i2= 0; There is I1 = = I2, and there is I1 = 1; then why I2 not become 1?

My idea at this point is this: because the integer constants in Java are based on int, and there is an automatic wrapper mechanism in Java, which means that I1,i2 is an integer type, But the bottom level is still based on the int type (incomprehensible words in Java there is another place that is arrays.aslist (T...args) He returns an array-based list, and if you change its size in the list, an exception is thrown [ Unsupportedoperationexception]), so point to the same value (int), so you can use the = = symbol can be understood, and if you are assigned to I1 by the new Integer (0), then, because it is new in the heap to open up a piece of memory, So with the = = symbol between the same object is compared memory address, then it is certainly false, and do not say the same object, and because the I2 is based on the Int class, in the potential to compare the weight is to return a false, although the surface looks like they are the same type!!

In Java, integer i1= 0; Integer i2= 0; Why do you use the = = symbol?

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.