码迷,mamicode.com
首页 > 编程语言 > 详细

java8 泛型声明 The diamond operator ("<>") should be used

时间:2016-03-01 12:47:49      阅读:1006      评论:0      收藏:0      [点我收藏+]

标签:

 

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.version is 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<>();

java8 泛型声明 The diamond operator ("<>") should be used

标签:

原文地址:http://www.cnblogs.com/yimiyan/p/5230301.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!