java set初始化问题

  set在执行add方法时,多次报空指针异常,后来发现Set初始化时,如果是

Set<Type> set = null;

这样的话,在执行 set.add(element)的时候会报空指针异常,具体原因不知,如果这样初始化:

Set<Type> set = new HashSet<>();

就不会,而

Set<Type> set = new Set<>();

会提示Cannot instantiate the type Set。

  总结来看,对java集合类的理解还是不够深入,接下来两天准备细细抓一抓这块儿
原文地址:https://www.cnblogs.com/kangyun/p/5479234.html