我该如何改变:
if (pAlarms[0].getMoIdentifier().isPresent()) {
Optional<AlarmValue[]> alarmValues = getAlarmsFromMo(pAlarms[0].getMoIdentifier().get());
}
进入ifPresent()
?
最佳答案
即使您要求使用 ifPresent()
,我认为在您的示例中使用 flatMap()
更有意义。有了它你应该能够做到这一点:
Optional<AlarmValue[]> alarmValues = pAlarms[0].getMoIdentifier().flatMap(this::getAlarmsFromMo)
关于java - 将 isPresent() 和方法调用更改为 ifPresent(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49550312/