I\'m trying to make something like this:
private String getStringIfObjectIsPresent(Optional object){ object.ifPresent(() ->{
Use the map-function instead. It transforms the value inside the optional.
map
Like this:
private String getStringIfObjectIsPresent(Optional object) { return object.map(() -> { String result = "result"; //some logic with result and return it return result; }).orElseThrow(MyCustomException::new); }