eclipse 没有在 java 8 项目中插入“菱形”运算符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24841572/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:07:51  来源:igfitidea点击:

eclipse not inserting "diamond" operator in a java 8 project

javaeclipsemaven

提问by Lili

I have a maven project configured to use Java 8 and all works fine, eclipse compiles code like:

我有一个配置为使用 Java 8 的 maven 项目并且一切正常,eclipse 编译代码如下:

Map<String,String> map = new HashMap<>();

It even complains about old-style code ("redundant specification of type arguments") when I set this on the Error/Warnings tab. The problem is, I can't work out how to make it use this syntax by default on autocompletion - I'm pretty sure I saw it working earlier but now whenever I ctrl-space to insert a constructor, it insists on adding the parameters, which I don't like.

当我在错误/警告选项卡上设置它时,它甚至会抱怨旧式代码(“类型参数的冗余规范”)。问题是,我无法弄清楚如何在自动完成时默认使用此语法 - 我很确定我之前看到它工作,但现在每当我按 ctrl-space 插入构造函数时,它都坚持添加参数,我不喜欢。

Can anybody hint what setting to check to make content assist insert <> instead of < String,String >? Or perhaps it's related to the fact I'm using Java 8 not Java 7, or that I'm on maven?

任何人都可以提示要检查什么设置以使内容辅助插入 <> 而不是 < String,String > 吗?或者这可能与我使用的是 Java 8 而不是 Java 7 的事实有关,或者我在使用 Maven?

采纳答案by Marco van Hilst

I had this issue just a few minutes ago and solved it half way through typing out an SO question.

几分钟前我遇到了这个问题,并通过输入一个 SO 问题解决了一半。

Eclipse's auto-complete apparently prioritized the old-style generic syntax after I had fiddled with the advanced content assist settings a while ago. Try resetting Java > Editor > Content Assist > Advancedto defaults; this was what fixed it for me and returned auto-complete to inserting the diamond syntax by default.

Eclipse 的自动完成功能显然优先考虑了旧式通用语法,因为我不久前摆弄了高级内容辅助设置。尝试重置Java > Editor > Content Assist > Advanced为默认值;这就是为我修复它并返回自动完成以默认插入菱形语法的原因。

回答by Bevor

I had the same problem but the solution to set everything to default didn't work for me. What worked for me is Java > Editor > Content Assist > Advancedand unchecking JPA Proposalsin the upper window.

我遇到了同样的问题,但是将所有内容设置为默认值的解决方案对我不起作用。对我Java > Editor > Content Assist > Advanced有用的是取消选中上方窗口中的JPA 提案

回答by grobmotoriker

I tried the two other solutions mentioned here, but none of them worked for me. What worked for me was Java > Editor > Content Assist > Advancedand checking Java Non-Type Proposalsin the upper box.

我尝试了这里提到的另外两个解决方案,但没有一个对我有用。对我有用的是Java > Editor > Content Assist > Advanced检查Java Non-Type Proposals上面的框。

On a different installation, this also had to be checked in the lower area, but it worked in both eclipse installations.

在不同的安装中,这也必须在下部区域进行检查,但它在两个 eclipse 安装中都有效。

回答by Michael Fayad

I observed this error when compiling with maven. To solve it, I had to fix my JAVA_HOME environment variable to the right JDK.

我在用 maven 编译时观察到这个错误。为了解决这个问题,我必须将我的 JAVA_HOME 环境变量修复到正确的 JDK。

回答by KFleischer

What worked for me is enabling/checking Java > Editor > Content Assist > Advanced >Java Proposals. (Upper part of the settings page)

对我有用的是启用/检查Java > Editor > Content Assist > Advanced >Java Proposals。(设置页面的上半部分)