[英]NullPointerException - check null on class
如何知道Employees.class 是否為空或不使用Java Reelection?
示例類: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 行的過程中檢查空異常?
嘗試通過執行以下操作檢查employees.getName()
是否為空:
employees.getName() != null
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.