我正在尝试迭代对象列表
Optional<QueryEntities> entities = InputYamlProcessor.process(ymlFilename);
entities.orElseThrow( ()->{
logger.error("Unable to parse YAL ,Correct YML and retry");
new NoExtractorDefinedException("Unable to parse YAL ,Correct YML and retry");
});
报错如下:
可选类型中的方法 orElseThrow(Supplier) 不适用于参数 (() -> {})
我在这儿怎么了?
如果 QueryEntities 类如下所示:
public class QueryEntities {
List<QueryEntity> entitiesList;
}
如何访问每个 QueryEntity 并检索其字段并打印。
最佳答案
Optional#orElseThrow
拿一个
Supplier<? extends X> exceptionSupplier
所以你必须提供一个:
entities.orElseThrow(() -> {
logger.error("Unable to parse YAL ,Correct YML and retry");
return new NoExtractorDefinedException("Unable to parse YAL ,Correct YML and retry");
});
关于java - 这里的 Optional<Class> 有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56539202/