ArrayList<Shop> shopList =getShopList();
Shop shop =  shopList.get(shopList.size()-1);
shopList.remove(0);
System.out.println(shop);
是不是会出现null异常

解决方案 »

  1.   

    ArrayList<Shop> shopList =getShopList();
            Shop shop =  shopList.get(shopList.size()-1);
            shopList.remove(0);
    数组移除一个对象,如果gc运行,是否会回收该对象(有可能会回收)
            System.out.println(shop);
    是不是会出现null异常(不会。即使是null对象也只是打印出null,除非你对null对象进行操作)
      

  2.   

    不可能出现
    只要 ArrayList<Shop> shopList =getShopList();
    shopList 指向的list不为null
    你的代码就不会出现nullpointexception();
    最多就是IndexOutOfBoundsException;
    gc不会对强引用可达的对象进行回收
      

  3.   

    不会,但是看了你的代码,会出现异常的。如果list为空,你的remove和get方法就报错啦