Java integer classes and unpacking and boxing

Source: Internet
Author: User


Package
Com.ilaw.boson.controller; Public classDemo { Public Static voidMain (string[] args) {Integer a=NewInteger (2000); intb =2000; Integer C=b; System.out.println (A= = b);//when True,integer and int are operated, a is removed from the boxSystem.out.println (b = = c);//when True,integer and int are operating, C is unboxingSystem.out.println (A = = c);//when the false,b is assigned, boxing calls the Integer.valueof method to box aa=NewInteger (10); C=10; System.out.println (A= = c);//false, the Integer.valueof method is called when a row boxing operation is performed, essentially two object comparisonsa=10; System.out.println (A= = c);//true, two objects are constructed by boxing, that is, through the Integer.valueof method, if the value is between 128-127, it is taken from the Integercache /*** Summary: * 1.Integer and int operations, the integer object is unboxing * 2. The address of an integer object is created differently by the new method * 3. Through in Teger a=10; The way the value is assigned will be boxed, boxing will call the integer valueof method * 4.Integer internally through the Integercache object to store the commonly used-128-127 integer object, when boxing will return in Tegerchache's Object **/ //description, when the integer type and int type are manipulated (equal, added), the unboxing operation is performed }}


Summarize:
When the 1.Integer and int are operating, the integer object is handled as a unboxing
2. When you create an address for an integer object by using the new method, different
3. When you assign a value by using an integer a=10, it will be boxed and the valueof method of the integer will be called.
The Integercache object is used internally by the 4.Integer to store an integer object between the common-128-127, which returns the Integerchache object when it is boxed.

Java integer classes and unpacking and boxing

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.