项目中常见NPE空指针异常
BigDecimal 转 String
BigDecimal bigDecimal = null;
System.out.println("bigDecimal.toString() = " + bigDecimal.toString());
String 转 BigDecimal
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空指针异常内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复