填原生态的坑(一)

©通过对Integer的了解,再探究其他七种类型在valueOf()方法是如何操作的,或者说自动装箱是如何操作的:

  • Boolean的两个值true和false都是cache在内存中的,且无须改造。new Boolean是另外的一块空间。
  • Byte在-128~127的256个值全部存放在cache中,和自己new  Byte的不是一块空间。
  • Short、Long两种类型的cache范围为-128~127,无法调整最大尺寸,如需扩展需要自己做。
  • Float、Double没有cache,要在实际场景中自己做。
  • 部分情况实例如下:

public static void main(String[] args) {
Boolean a=true;
Boolean b=true;
Byte a1=-128;
Byte b1 =-128;
Byte a2 = 127;
Byte b2 = 127;
System.out.println(a==b);
System.out.println(a1==b1);
System.out.println(a2==b2);
}

猜你喜欢

转载自www.cnblogs.com/hisir/p/9878062.html
今日推荐