After the Java SE 1.5 release and later, the automatic boxing feature is available.
Auto-boxing, "wrapping" the underlying type into one type:
Basic Type-wrapper class
The following procedure triggers an automatic boxing process:
Integer count = 1;
Double amount = 2.0D
From the Javadoc API, the wrapper class provides a way to manipulate the underlying type of encapsulation:
Type conversions, such as float-to-int
Comparison
...
It is worth noting that for values between [-128, 127], automatic boxing uses caching to provide memory efficiency.
That is, automatically boxing the value of the range, the resulting wrapper class memory address is not changed.
For example
Integer a = 129;
Integer B = 129;
System.out.println (A = = B);//Output True
Practice:
1, automatic boxing appears in the variable declaration;
2, consider the use of one of the scenarios, the basic types need to compare, type conversion and other operations;
3, if you need to compare the wrapper class = =, it is recommended to convert to the underlying type, and then proceed.
To avoid the effect of the cache value range [-128, 127] on = = Comparison results.
Java basic Type Auto-boxing (autoboxing)