public ValueA map(ValueB valueB, Date date) { Optional<ValueC> valueCOpt = find(valueB); if (valueCOpt.isPresent()) { ValueC valueC = valueCOpt.get(); // call many getters on valueC and do a lot of logic with it. return map(/*some parameters*/); } return null; }
That seems pretty ugly. The advantage of optionals has completely disappeared here. I read that it is better to use map or flatMap instead of get . But is it really useful if I replace each recipient, for example
valueC.getFieldA()
with
valueCOpt.map(ValueC::getFieldA)
Do you know some general or best practices here?
source share