I have a Java Optional variable that I'm using as below.
Optional<Forms> formsOptional = input.data().get().forms();
if(formsOptional.isPresent()) {
this.doSomething(myValue, forms.get());
} else {
this.doSomething(myValue, Forms.builder().names(myList).build());
}
In this case, doSomething method is a void method that does something. As this is a void method, I'm confused about how I can use the map().orElseGet(), as I don't have anything to transform as well. Any suggestions to optimize this piece of code using any Java8 Optional techniques would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire