Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - The difference between int and Integer (equal to and = =)
The difference between int and Integer (equal to and = =)
Here, let me first talk about the concept of constant pool and memory storage in jvm.

1: Constant pool is a pool for storing constants (why there is such a thing as constant pool is not detailed here, but you can look at the memory analysis of java virtual machine).

2.2. The location of int/integer in memory: First, give an example:

Everyone should be familiar with the above three methods of creating integers, but their storage locations in memory are quite different.

3: = = Comparative description

4. Note: The new integer (int num) and int comparison will be cast. Creating a comparison between Integer and int in the form of new will force the conversion of new Integer () to int type, as shown in the following figure:

5. Case:

6.6: Constant Pool Location in JVM

? Before 1.7, it exists in the method area.

? 1.7, which exists in the permanent generation.

? After 1.7, it exists in the meta space, which is the direct memory of pc, because 1.8 deletes the permanent generation.

7: equals () method

Directly see whether Integer rewrites the equals method of Object, and directly compare whether it is equal. The equivalence is true.