One, type encapsulation device
For performance reasons, Java does not discard basic data types, which can be an unacceptable overhead if they are always used in the form of objects. Although the basic types provide the benefits of performance, they sometimes require representations of objects. For example, the base type cannot be passed as a reference, and the standard data structure of the Java implementation can only manipulate objects. In order to handle these cases, Java provides a type wrapper.
Second, automatic packing
The process of encapsulating numeric values into an object is called unpacking, and the process of extracting values from the type wrapper is called unpacking. Java already supports automatic boxing and automatic unpacking. When you need to convert a base type to an object, automatic boxing will inevitably occur. When you need to convert an object to a base type, automatic unpacking will inevitably occur. You should reasonably reduce the use of type wrappers when writing code to avoid unnecessary performance overhead.
classSolution {Static intunbox (Integer i) {returnI//Automatic Unpacking } StaticInteger Box (inti) {returnI//Automatic Boxing } Public Static voidMain (string[] args) {intA = unbox (100);//Automatic BoxingInteger b = Box (500); }}
Java notes: Auto-boxing