package Day04ExceptionDemo;
import java.util.Objects;
public class Demo02RequireNonNull {
public static void main(String[] args) {
Object obj = null;
Demo01(obj);
}
private static void Demo01(Object obj) {
/*if (obj == null){
throw new NullPointerException("传入的对象是null,不合法!");
}*/
// Objects.requireNonNull(obj);
Objects.requireNonNull(obj,"传入的对象是null,不合法!");
}
}
Objects的requireNonNull方法(检测空指针,抛出异常)
最新推荐文章于 2024-05-28 20:20:27 发布