11
空检查在增强的for循环中
在Java中的for循环中防止空值的最佳方法是什么? 这看起来很丑: if (someList != null) { for (Object object : someList) { // do whatever } } 要么 if (someList == null) { return; // Or throw ex } for (Object object : someList) { // do whatever } 可能没有其他办法。他们是否应该将其放入for构造本身中,如果为null,则不要运行循环?