包装类数据缓存

    技术2023-12-28  82

    Java中只是对部分基本数据类型对应包装类的部分数据进行了缓存:

    1.对于包装类Byte,Integer,Short,Long在范围(-128~127)(包括-128和127)对数据进行缓存:

    public class HC { public static void main(String[] args) { Integer a = 12; Integer b = 12; System.out.println(a==b);//结果true Integer a = 128; Integer b = 128; System.out.println(a==b);//结果false } }

    2.对于包装类Float和Double没有数据缓存范围;

    public class HC { public static void main(String[] args) { Double a = 12.0; double b = 12.0; System.out.println(a==b);//结果false } }

    3.对于包装类Character的数据缓存范围为 0~127(包括0和127);(同1)

    4.包装类Boolean的数据缓存为true和false;

    public class HC { public static void main(String[] args) { Boolean a = true; Boolean b = true; System.out.println(a==b);//结果ture } }

     

    Processed: 0.012, SQL: 9