浅析Java编程报错:explicit type argument xx can be replaced with

一、警告:“explicit type argument xx can be replaced with......”

1、问题背景

  开发时有警告信息: explicit type argument xx can be replaced with<>,完整的信息如下:

explicit type argument xxx can be replaced with<>, 
inspection info: reports all new expressions with type arguments
which can be replaced with diamond type

  说的意思是:显式类型参数xx可以替换为<>

2、问题原因及解决

  问题就出在 List<Entity> list = new ArrayList<Entity>(); 这种泛型只需写在 List<> 里边即可。

  List 里边声明了泛型以后,再在 ArrayList 里边声明是重复冗余的。改成如下:

List<Entity> list = new ArrayList<>();

  改后警告消失。

posted @ 2017-08-09 22:40  古兰精  阅读(1138)  评论(0编辑  收藏  举报