使用集合接口的时候应该使用通用类型代替具体的实现类型
2015-12-28 09:04
447 查看
Sonar静态代码检查发现下面缺陷:
Declarations should use Java collection interfaces such as “List” rather than specific implementation classes such as “LinkedList”
The purpose of the Java Collections API is to provide a well defined hierarchy of interfaces in order to hide all implementation details.
Implementating classes must be used to instantiate a new collection, but the result of an instantiation should immediately be stored in a variable whose type is a
Java Collection interface
就是说譬如你要实现一个HashMap的集合,不用直接用 HashMap hm = new HashMap();这样的方式去实例化,而是要用 Map hm = new HashMap();来做。
同理LinkedList的实例化也是 List ll = new LinkedList();这样的方式去实例化
Declarations should use Java collection interfaces such as “List” rather than specific implementation classes such as “LinkedList”
The purpose of the Java Collections API is to provide a well defined hierarchy of interfaces in order to hide all implementation details.
Implementating classes must be used to instantiate a new collection, but the result of an instantiation should immediately be stored in a variable whose type is a
Java Collection interface
就是说譬如你要实现一个HashMap的集合,不用直接用 HashMap hm = new HashMap();这样的方式去实例化,而是要用 Map hm = new HashMap();来做。
同理LinkedList的实例化也是 List ll = new LinkedList();这样的方式去实例化
相关文章推荐
- sort--排序函数
- Win7启动事件
- Swift  循环语句
- log10/log2--求常用对数/以2为底的对数
- 每日一vim(7)自动补齐CTRL+N/CTRL+P
- log--求自然对数
- struts文件上传demo
- Myeclipse的problem中出现cannot be read or is not a valid ZIP file解决
- exp--求以e为底的指数函数
- SAS学习笔记之《SAS编程与数据挖掘商业案例》(2)数据获取与数据集操作
- SAS学习笔记之《SAS编程与数据挖掘商业案例》(2)数据获取与数据集操作
- abs--数值的绝对值和复数的模值
- 12.27总结
- LeetCode Count and Say
- iOS视图控制对象生命周期-init、viewDidLoad、viewWillAppear、viewDidAppear、viewWillDisappear、view
- HDFS的特性和目标
- atan2--四象限的反正切函数
- 《Android源码设计模式解析与实战》读书笔记(十二)
- 公共类CommonUtil中不应该有公开的构造函数
- csch和acsch--双曲余割和反双曲余割函数