【发布时间】:2021-06-04 03:58:05
【问题描述】:
CCMT c = new CCMT();
c.ccd = null;
Optional<String> cType = Optional.ofNullable(ccmtRequest).map(CCMT::getCcd).map(MOEH::getDestCtry);
System.out.println(cType.isPresent()); // false
if(cType.isPresent() && cType.get().equalsIgnoreCase("CCMT") || cType.get().equalsIgnoreCase("CCWC")) {
System.out.println("wfegr");
}
错误:异常NoSuchElementException
为什么 cType.get() 语句被执行,即使首先 条件是 false 本身?
【问题讨论】:
-
它正在正常工作。你只需要在正确的地方使用括号
标签: java if-statement operators relational