首页 > 编程语言 > 详细

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

时间:2016-03-01 12:45:01      阅读:2035      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!