I have optional object:
Optional newestDetail;
I would like to return newestDetail.getId() or if newestDetail
newestDetail.getId()
newestDetail
Map the value to an Optional with the id field and turn that one into a null value if it is empty:
Optional
null
return newestDetail.map(Detail::getId).orElse(null);