参考博客
参考博客1
:
标题:Optional是个好东西,你会用么?(全面深度解析)
链接:https://blog.csdn.net/DBC_121/article/details/104984093?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166174195316782390593442%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166174195316782390593442&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~pc_rank_34-1-104984093-null-null.142v42pc_rank_34,185v2control&utm_term=Optional%E6%98%AF%E5%81%9A%E4%BB%80%E4%B9%88%E7%94%A8%E7%9A%84&spm=1018.2226.3001.4187
参考博客2
:
标题:Optional用法
链接:https://blog.csdn.net/Carrots_vegetables/article/details/109289415?ops_request_misc=&request_id=&biz_id=102&utm_term=Optional&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-0-109289415.nonecase&spm=1018.2226.3001.4187
参考博客3
:
标题:Optional类的map和flatMap的区别
链接:https://blog.csdn.net/DataB/article/details/107072400?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166175162116782246428733%2522%252C%2522scm%2522%253A%252220140713.130102334…%2522%257D&request_id=166175162116782246428733&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduend~default-1-107072400-null-null.142v42pc_rank_34,185v2control&utm_term=optional%E7%9A%84map%E5%92%8Cflatmap%E5%8C%BA%E5%88%AB&spm=1018.2226.3001.4187
参考博客4
:
标题:Java8的Optional是不是鸡肋?
链接:https://blog.csdn.net/g6U8W7p06dCO99fQ3/article/details/118282653?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166175539916781667878924%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=166175539916781667878924&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_ecpm_v1~pc_rank_34-2-118282653-null-null.142v42pc_rank_34,185v2control&utm_term=optional%E7%9A%84%E7%BC%BA%E7%82%B9&spm=1018.2226.3001.4187
代码参考
public class PublicTest {
// isPresent方法 、 get()方法 、 orElse方法 、 map()方法
@Test
public void test(){
Map map = new HashMap<>();
map.put("x1","xx1");
map.put("x2","xx2");
Optional
执行结果
# 1
{x1=xx1, x2=xx2}
# 2
{x1=xx1, x2=xx2}
# 3
xx1
# 4
xxx222