问题描述
No value present, app直接报错出来,直接找optional为什么会报这个错,
/**
* If a value is present in this {@code Optional}, returns the value,
* otherwise throws {@code NoSuchElementException}.
*
* @return the non-null value held by this {@code Optional}
* @throws java.util.NoSuchElementException if there is no value present
* @see Optional#isPresent()
*/
public T get() {
if (value == null) {
throw new NoSuchElementException("No value present");
}
return value;
}
找到 get使用的地方 ,查看get前面是不是空.
CustomerBaseInfo customerBaseInfo =
customerService.getCustomer(relavant.getCardId(), Integer.valueOf(relavant.getCardType())).get();
发现getCustomer获取到的optional是空.