java - Java 项目中的 Eclipse 警告 "Replace the type specification in this constructor call with the diamond operator (' < >')"

标签 java eclipse java-8 sonarlint sonarlint-eclipse

Eclipse 询问 Replace the type specification in this constructor call with the diamond operator ('<>') 时是什么意思? ,既然所说的运算符(operator)已经在那里了?

然后我将光标放在蓝色下划线的内容上,然后按 F2 了解更多信息,然后我收到此消息 ( Replace the type specification in this constructor call with the diamond operator ('<>') ):

An Eclipse warning saying "Replace the type specification in this constructor call with the diamond operator ('<>')"

如果我删除Object从内部<> ,Eclipse还是不高兴:

An Eclipse warning saying "Replace the type specification in this constructor call with the diamond operator ('<>')"

编辑

我们确保

  • java.util.List已导入
  • 更改已保存
  • Project -> Clean...命令已应用

蓝色警告仍然不会消失。

最佳答案

这似乎是 SonarLint 中的一个错误的钻石操作符检查器,而不是 Eclipse JDT:请参阅 the source code of SonarLint that contains the message .

另请参阅:SonarJava Rule 2293: The diamond operator ("<>") should be used

解决方案:

禁用SonarJava规则2293使用Eclipse警告泛型类型>改为冗余类型参数(1.7 或更高)

关于java - Java 项目中的 Eclipse 警告 "Replace the type specification in this constructor call with the diamond operator (' < >')",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47396437/

相关文章:

java - 使用 Optional.of() 有真正的理由吗?

Spring 4 无法执行 Java 8 默认方法

java - Java 8 中关于 Comparator 的误解

java-8 - 为什么需要在管道中进行短路操作...在 Java 8 中

java - 对 Java Date 对象进行排序和比较会产生意外结果

java - 在页面重新加载时重置 Java Applet

java - 客户端排序 + Hibernate 分页?

java - 工作集是否等同于 Visual Studio 中的解决方案

Java堆转储和堆分析后的堆大小不同

Eclipse 插件 - 与文件扩展名和透视图关联的编辑器