记录JAVA8中Optional的使用
为什么推出Optional **空指针异常(NullPointerException)**空指针异常特别容易在调用对象的某个方法上,我们平常判空时,可能是以下 if (user != null) { Address address = user.getAddress(); if (address != null) { Country country = address.getCountry(); if (country != null) { String isocode = country.getIsocode(); if (isocode != null) { isocode = isocode.toUpperCase(); } } } } 但是这样会显得特别杂乱无章 ...