java8 泛型声明 The diamond operator ("<>") should be used
2016-03-01 11:24
555 查看
The diamond operator ("<>") should be used
Java 7 introduced the diamond operator (<>) to reduce the verbosity of generics code. For instance, instead of having to declare a
List's type in both its declaration and its constructor, you can now simplify the constructor declaration with
<>, and the compiler will infer the type.
Note that this rule is automatically disabled when the project's
java.source.versionis lower than
7.
Noncompliant Code Example
List<String> strings = new ArrayList<String>(); // Noncompliant Map<String,List<Integer>> map = new HashMap<String,List<Integer>>(); // Noncompliant
Compliant Solution
List<String> strings = new ArrayList<>(); Map<String,List<Integer>> map = new HashMap<>();
相关文章推荐
- 字符串(二)--来自《Java编程思想第四版》第13章
- Java中equals(),hashCode(),==的对比使用
- 【leetcode】【53】Maximum Subarray
- Spring的任务调度
- Java中重载与重写的区别
- Java基础(三):Java常用API
- [LeetCode]-319. Bulb Switcher (Medium)(Java)
- java 实例化的时候得执行顺序
- 从头认识SpringBatch批处理框架---SkipListener
- eclipse中创建maven module报错:Could not calculate build plan:Plugin.........
- eclipse的maven插件自动下载源码
- spring源码分析—BeanFactory
- Eclipse 小记 2
- Java打印流的的使用过
- java面向对象编程基础-读书笔记
- javassist使用中遇到的问题记录
- javassist使用中遇到的问题记录
- Java中怎么通过身份证解析出:年龄、性别、出生日期。
- 几种任务调度的 Java 实现方法与比较
- JAVA矩阵包JAMA学习