Get field of optional object or return null

后端 未结 1 1575
暖寄归人
暖寄归人 2021-02-13 20:18

I have optional object:

Optional newestDetail;

I would like to return newestDetail.getId() or if newestDetail

相关标签:
1条回答
  • 2021-02-13 20:42

    Map the value to an Optional with the id field and turn that one into a null value if it is empty:

    return newestDetail.map(Detail::getId).orElse(null);
    
    0 讨论(0)
提交回复
热议问题