I\'m trying to make something like this:
private String getStringIfObjectIsPresent(Optional object){ object.ifPresent(() ->{
I'd prefer mapping after making sure the value is available
private String getStringIfObjectIsPresent(Optional object) { Object ob = object.orElseThrow(MyCustomException::new); // do your mapping with ob String result = your-map-function(ob); return result; }
or one liner
private String getStringIfObjectIsPresent(Optional object) { return your-map-function(object.orElseThrow(MyCustomException::new)); }