黑马程序员:自动装箱与拆箱、

来源:互联网 发布:2020软件是什么 编辑:程序博客网 时间:2024/04/29 21:28
---------------------- android培训、java培训、期待与您交流! ---------------------- 

自动装箱

Integer num1=12;

自动拆箱

System.out.println(num1+12);//24

基本数据类型的对象缓存:

Integer num1=12;

Integer num2=12;

System.out.println(num1==num2);//true

Integer num3=129;

Integer num4=129;

System.out.println(num3==num4);//false

Integer num5=Integer.valueOf(12);

Integer num6=Integer.valueOf(12);

System.out.println(num5==num6);//true

-128~127内的整数,即byte范围内的整数,如果该数值已存在,这不会开辟新空间。

享元模式(flyweight):

有很多个小的对象,里面有很多属性相同,把他们变成一个对象,那些不同属性作为方法的参数成为外部状态,相同属性成为内部状态;

解决了大量相同对象被多次实例化,从而导致内存被大量占用的情况

 

---------------------- android培训、java培训、期待与您交流! ----------------------详细请查看:http://edu.csdn.net/heima
原创粉丝点击