我是靠谱客的博主 外向书本,这篇文章主要介绍项目中常见NPE空指针异常,现在分享给大家,希望可以做个参考。

项目中常见NPE空指针异常

BigDecimalString 
BigDecimal bigDecimal = null;
System.out.println("bigDecimal.toString() = " + bigDecimal.toString());
StringBigDecimal
String string = null;
BigDecimal bigDecimal = new BigDecimal(string);
System.out.println("bigDecimal = " + bigDecimal);
List<String> list = null;
String s = list.get(0);
System.out.println("s = " + s); 
UserInfo userInfo = null;
String userName = userInfo.getUserName();
System.out.println("userName = " + userName);
String aa = null;
boolean bb = aa.equals("bb");
System.out.println("bb = " + bb);
List<String> strings = null;
List<String> strings1 = Collections.emptyList();
System.out.println("strings = " + strings); // null
System.out.println("strings1 = " + strings1); // []

boolean empty = CollUtil.isEmpty(strings);
boolean empty1 = CollUtil.isEmpty(strings1);
System.out.println("empty = " + empty);  // true
System.out.println("empty1 = " + empty1); // true
String str = null;
Map map = new ConcurrentHashMap<>();
map.put(str,"abc");
map.put("aaa",null);
System.out.println("map = " + map);
ZoneInfo zoneInfo = null;
zoneInfo.setName("aaa");
System.out.println("zoneInfo = " + zoneInfo);

在这里插入图片描述

最后

以上就是外向书本最近收集整理的关于项目中常见NPE空指针异常的全部内容,更多相关项目中常见NPE空指针异常内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(129)

评论列表共有 0 条评论

立即
投稿
返回
顶部