在此代码中,student.getXx()
返回一个对象
有没有办法只用一个条件来检查student
是否为空?
代码:
public class HuangFeilongTest {
public static void main(String[] agrs){
Student student = new Student(null);
// it will throw a NullPointerException
/*if(student.getXx().getA() != null){
System.out.println("Can't execute this");
}*/
//I must write three conditions to determine student.getXx().getA() is null or not
//Can I write one condition to determine
if(null != student && null!=student.getXx() ){
if(student.getXx().getA()!=null){
System.out.println("123");
}
}
}
}