如何知道Employees.class是否为null或不使用Java Relection?
示例类:Employees.class
问题:
Employees.Class
public class Employees{
private Long id;<br>
private String kodStuff;<br>
private String Name;<br>
//Getter and Setter<br>
}
示例处理方法:
public void check(){
Employees employees = new Empoyees;
employees.setName("Mikel");
employees.setKodStuff("KL370");
//employees not save yet and process redirect check value of Name wuth return boolean
Boolean empty = checkName(employees);
}
public boolean checkName(Employees employees){
boolean notNull = false;
if(employees !=null && StringUtils.isNotBlank(employees.getName())){ // this is line 11
notNull = true;
}
return notNull;
}
在第11行输出异常:
java.lang.NullPointerException
如何在第11行的过程中检查空异常?
答案 0 :(得分:0)
通过执行以下操作,尝试检查employees.getName()
是否为空:
employees.getName() != null