Packing class and automatic unboxing

Source: Internet
Author: User

First, Packaging class

Wrapper class Definition: Object type, which encapsulates the data type with an object-oriented approach. Each wrapper class corresponds to a basic data type, such as Boolean, Char, Byte, short, integer, etc. that correspond to Boolean, char, Byte, short, and int, and have corresponding properties and methods.

Function: ① is very convenient for data type conversion, such as the character type of the number "243", if you want to convert to integer type packaging class is very convenient.

② the wrapper class is also used when the data type that needs to be worn in some cases is an object type.

public class Test {
public static void Main (string[] args) {
Integer i = new integer (1);
Int J = I.intvalue () + 1;
System.out.println (i);
System.out.println (j);
}
}

Second, automatic unpacking and packing

Automatic unpacking and boxing greatly facilitates the operation between the basic data type and the wrapper type. The auto-boxing feature can package the base data type as the appropriate wrapper type, while the auto-unpacking feature can unpack the wrapper type to the appropriate base data type.

public class Test {
public static void Main (string[] args) throws exception{
Integer i = 1;
Int J = i + 1;
System.out.println (i);
System.out.println (j);
}
}

  

Packing class and automatic unboxing

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.