It seems to me Optional adds little to code flow control and missing values handling. If a value behind an optional is not found, one still have to deal with absence of the value - then what's the point?
Compare:
Optional someMissingVal = codeThatReturnsOptional.getOptionalValue().orElse(null);
if( someMissingVal == null){
throw(new NullPointerException());
}
else return someMissingVal.get();
vs
Type someMissingVal = codeThatReturnsType.getTypeValue();
if( someMissingVal == null){
throw(new NullPointerException());
}
else return someMissingVal;
So what's the big deal and how do I use Optional to harness its full power in the scenario above - as opposed to the "old style" missing value handling?