这几天研究了一下JDK14,发现它处理NPE的方式,真香!
关注“Java技术迷”升职加薪不脱发!
粉丝福利:小编会从今天留言的小伙伴中赠送6.66元现金红包。
娱乐抽奖,大家随缘积极参与啦,给生活一点小幸运~感谢大家的支持
String city = employee.getDetailInfos().getRegistryAddress().getCity();
-XX:+ShowCodeDetailsInExceptionMessages
Exception in thread "main" java.lang.NullPointerException:
Cannot invoke "RegistryAddress.getCity()" because the return value of
"com.developlee.java14.helpfulnullpointerexceptions.HelpfulNullPointerException$DetailInfos.getRegistryAddress()" is null
at com.developlee.java14.helpfulnullpointerexceptions.HelpfulNullPointerException.main(HelpfulNullPointerException.java:10)
Cannot invoke "String.toLowerCase()" because the return value of "getEmailAddress()" is null
Employee employee = null;
employee.getName();
"com.developlee.java14.helpfulnullpointerexceptions.HelpfulNullPointerException$Employee.getName()"
because "employee" is null
Cannot invoke
"com.developlee.java14.helpfulnullpointerexceptions.HelpfulNullPointerException$Employee.getName()"
because "<local1>" is null
关注Java技术迷看更多干货
更多精彩推荐
![]()
点分享 点点赞 点在看
