ListschedultCustomProductIds=new ArrayList<>();
if(schedultCustomProductIds!=null) {
scheduleCustomProductList = scheduleCustomProductDao.getByIds(schedultCustomProductIds);
}
这样是不能阻挡getByIds()方法的执行的(size=0和null是不同的,new完以后,是会给他分配内存的,是size=0,因为给他分内存了,所以他不是null,if判断也就不生效了.
应该下面这样判断:
if(schedultCustomProductIds!=null&&schedultCustomProductIds.size()>0)或者if(!schedultCustomProductIds.isEmpty())
本文探讨了在Java中检查集合是否为空的正确方法,强调了仅检查对象引用是否为null是不够的,还应检查集合的size是否大于0,避免了因误以为集合为空而引发的潜在错误。
1303

被折叠的 条评论
为什么被折叠?



