categoriesJAVA基础语法 2021-04-25 java基础1 装箱拆箱1234567public class IntegerDemo { public static void main(String[] args) { Integer i=1;//自动装箱Integer i=Integer.valueOf(1); int a=i;//自动拆箱int a=i.intValue(); }}装箱操作会创建对象,频繁的装箱操作会消耗许多内存,影响性能,所以可以避免装箱的时候应该尽量避免。 面试题:Integer num=0; num+=1;在这个过程中做了哪些操作? 答:先自动拆箱,后自动装箱。变成Int再加一,再变回integer。