Packaging, boxing, unboxing, automatic boxing, automatic unboxing

1. Packaging

Overview: Java provides two type systems, basic types and reference types. The use of basic types is efficiency. However, in many cases, objects are created and used because objects can do more functions.

If you want our basic types to operate like objects, you can use the packaging classes corresponding to the basic types, as follows:

Basic data types are very convenient to use, but there is no corresponding method to manipulate these basic types of data.
You can use a class to pack the basic types of data and define some methods in the class. This class is called a wrapper class.
We can use the class To manipulate these basic types of data

2. Packing and unpacking

The process of conversion back and forth between the basic type and the corresponding packaging object is called "boxing" and "unboxing":
●Boxing: Convert from the basic type to the corresponding packaging object.
●Unboxing: Convert from packaging objects to corresponding basic types.
Take Integer and int as examples: (just understand the code)
basic value ---> packaging object

Package object --->Basic value

3. Automatic boxing and automatic unboxing

4. Conversion between basic data types and strings

Guess you like

Origin blog.csdn.net/weixin_51980491/article/details/112809048