标签:eps exception 开始 null nts ret poi turn 判断
public class Counter {
public int countSheeps(Boolean[] arrayOfSheeps) {
int counter = 0;
for (Boolean sheep : arrayOfSheeps) {
if (sheep != null && sheep) {
counter++;
}
}
return counter;
}
}
刚开始,用的if (sheep)
,报错java.lang.NullPointerException空指针异常。
当一个对象的值为空时,并且没有判断为空的情况。可以试着把下面的代码前加一行代码:
if(rb!=null);
标签:eps exception 开始 null nts ret poi turn 判断
原文地址:https://www.cnblogs.com/391halsey/p/12909127.html