一、警告:“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<>();

  改后警告消失。

相关文章:

  • 2021-04-19
  • 2021-08-28
  • 2021-09-13
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
猜你喜欢
  • 2021-08-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-03-09
相关资源
相似解决方案