1.意料之外1 short a=1; a=a+1;//编译错误 1为int型需要进行强转 a+=1;//编译正确 +=操作符会进行隐式自动类型转换
2.Integer中IntegerCache
public class Test {
/**
* Cache to support the object identity semantics of autoboxing for values between
* -128 and 127 (inclusive) as required by JLS.
* <p>
* The cache is initialized on first usage. The size of the cache
* may be controlled by the {@code -XX:AutoBoxCacheMax=<size>} option.
* During VM initialization, java.lang.Integer.IntegerCache.high property
* may be set and saved in the private system properties in the
* sun.misc.VM class.
* ************************* IntegerCache
* 缓存以支持之间值的自动装箱的对象标识语义
* -JLS要求的128和127(含)。
* 缓存在第一次使用时初始化。缓存的大小
* 可以由{@code-XX:AutoBoxCacheMax=<size>}选项控制。
* 在VM初始化期间,java.lang.Integer.IntegerCache.high属性
* 可以在中的专用系统属性中设置和保存
* sun.misc.VM类。
*/
public static void main(String[] args) {
Integer a = 127, b = 127, c = 128, d = 128;
System.out.println(a == b);
// 输出true
System.out.println(c == d);
// 输出false
}
}
3.