アルジュン:
私が使用しようとしていますStream
中にorElse
、エラーを理解するのに困難を持ちます。
collectorConfiguration = Optional.ofNullable(recapPlacement.getAttId())
.map(attId -> Optional.ofNullable(processorEngine.buildFrimFromAttId(attId))
.orElseThrow( () -> new OmegaException("UnableToFirmByAttId", recapPlacement.getAttId())))
.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull)
.findFirst())
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnetCode", recapPlacement.getPnetCode()))
);
全体的に上記のコードでは私がしようとしています
取得
collectorConfig
場合attId
はnullではありません場合は
attId
nullでなく、collectorConfig
そのためには見られないattId
、私は例外をスローしています場合
attId
はnullが、その後で私が使用していますpnet
取得するには、コードをcollectConfig
ストリーミングcollectConfigurations
リスト場合
collectConfig
のために発見されないpnetCode
、私は例外をスローしています
これは、コンパイルエラー「与えているTarget type of a lambda expression must be an interface
で」orElse
ブロックを。
また:
あなたは交換したいかもしれません
.orElse( () -> Optional.ofNullable(collectorConfigurations.stream() //getting error here
でOptional.orElseGet
これを期待Supplier
通り:
.orElseGet( () -> Optional.ofNullable(collectorConfigurations.stream() ...
上記に加えて、あなたは必要はありませんOptional.ofNullable
サプライヤーに
.orElseGet( () -> collectorConfigurations.stream()
.filter(cc -> recapPlacement.getPnetCode().equals(cc.getPnetCode()))
.filter(Objects::nonNull) //non-null filtered
.findFirst()) // optional
.orElseThrow( () -> new OmegaException("CollectorCouldNotMapForPnet...