The difference between int and Integer, why does Java design a wrapper class?

1. The default value is different

As a member variable, the initial default value of int is 0 , while Integer is null .

2. The storage memory location is different

Integer is a class whose objects are stored in the heap , and int is a basic data type stored in the stack .

3. The role is different

The Integer class encapsulates many properties and methods, which will be more flexible to use .

Why does Java design wrapper classes for basic types?

Because Java is originally an object-oriented language, the design of the packaging class is also helpful to introduce the support of the collection framework, and the packaging class also provides the conversion method with the basic data type, which is also called boxing and unboxing . With the basic type of packaging class, it is beneficial to the development of developers and can better reflect the characteristics of object-oriented languages.

Guess you like

Origin blog.csdn.net/m0_62565675/article/details/131649723