Java Packing and unpacking parsing

Source: Internet
Author: User

/**
* After jdk1.5, Java provides automatic unboxing for basic data types to corresponding application data types
* Whether auto-unpacking or auto-boxing is a method of applying a data type, the base data type is no method callable

* Conceptually, unpacking is from the application data type to the basic data type, boxing from the base data type to the application data type
*/
An automatic boxing operation is performed, the actual is: Integer I1 = integer.valueof (100);
The ValueOf method caches the object when the value is between 128 and 127, if it does not exist in the cache, creates if it exists, and does not create a direct fetch
Integer i1 = 100;
The action that was actually taken by this operation is: int i2 = I1.intvalue (), an automatic unpacking operation occurred
int i2 = I1;

/**
* All the following conditions will appear
* Number outside the -128~127
Integer i1 = 200;
Integer i2 = 200;
System.out.println ("I1==i2:" + (I1==I2)); The result is false
The number within the -128~127
Integer i3 = 100;
Integer i4 = 100;
System.out.println ("I3==i4:" + (I3==I4)); Result is True
*/

Integer i3 =new integer (100);
Integer i4 =new integer (100);
System.out.println ("I3==i4:" + (I3==I4));//Display False
This occurs because automatic unboxing and auto-boxing operations do not occur on the

In fact, the other seven kinds should also be boxed unpacking operation, here do not do a demonstration, interested can see the source code

Java Packing and unpacking parsing

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.