elseCondition當當前它正在拋出時,這是否可以在一行中寫入nullPointer在我的場景中,returnValue 是一個字符串,它為空。我想寫的條件是if (returnValue != null) { return returnValue;} else if (elseCondition != null) { return elseCondition.getValue();} else { return null;}Optional.ofNullable(returnValue).orElse(elseCondition.getValue()) //throws nullPointer as elseCondition is nullclass ElseCodnition { private String value; getValue() {...}}
java8 orElse(null.getValue()) 怎么處理
慕無忌1623718
2022-10-07 17:02:40