在带有 JDK 8 的 IDEA 中使用 Eclipse 编译器时出现“java:名为 XXX 的重复方法”问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19137261/
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-09-19 21:14:01  来源:igfitidea点击:

"java: Duplicate methods named XXX" issue when using Eclipse compiler in IDEA with JDK 8

eclipsecompiler-constructionintellij-ideajava-8

提问by Gelin Luo

With the following simple class I get java: Duplicate methods named spliterator with the parameters () and () are inherited from the types java.util.List<T> and java.lang.Iterable<T>error if using Eclipse compiler in IDEA with JDK 8:

java: Duplicate methods named spliterator with the parameters () and () are inherited from the types java.util.List<T> and java.lang.Iterable<T>如果在带有 JDK 8 的 IDEA 中使用 Eclipse 编译器,则使用以下简单类会出错:

public class Java8Test {
    public static interface Traverable<T> extends Iterable<T> {}
    public static interface List<T> extends Traverable<T>, java.util.List<T> {}
}

If change the compiler to javac, then there is no error. The error also gone if switched to JDK 6 with eclipse compiler.

如果将编译器更改为 javac,则没有错误。如果使用 eclipse 编译器切换到 JDK 6,错误也会消失。

IDEA version: 12.1.5

想法版本:12.1.5

回答by Fabian Streitel

I got the same error when trying to compile Java 7 code with a Java 8 JDK.

尝试使用 Java 8 JDK 编译 Java 7 代码时遇到了同样的错误。

The solution that worked for me was changing the JRE configured in Eclipse to a Java 7 one: Window -> Preferences -> Java -> Installed JREs. Edit the existing one and select a directory containing a Java 7 JDK.

对我有用的解决方案是将 Eclipse 中配置的 JRE 更改为 Java 7 之一:Window -> Preferences -> Java -> Installed JREs. 编辑现有的并选择一个包含 Java 7 JDK 的目录。

回答by El Marce

I had the same issue. It seem that Eclipse's 4.3 JTD is not carrying on well with Java8. On the words of Stephan Herrmann (CLA):

我遇到过同样的问题。Eclipse 的 4.3 JTD 似乎不能很好地与 Java8 兼容。关于 Stephan Herrmann (CLA) 的话:

A Java 7 compiler should never try to compile against a JRE 8. True compatibility for the scenario is not specified anywhere and may not even be possible because of default methods that have been added to the libraries in a way that ensures runtime compatibility of old code but notcompile time compatibility with a Java 7 compiler and new libraries. Hence I'm marking this bug as invalid, it's s.t. we cannot support by design.

Java 7 编译器不应尝试针对 JRE 8 进行编译。该场景的真正兼容性并未在任何地方指定,甚至可能无法实现,因为已将默认方法添加到库中以确保旧代码的运行时兼容性但 与Java 7编译器和新库编译时的兼容性。因此,我将此错误标记为无效,这是我们无法通过设计支持的。

You may read more in here:

您可以在此处阅读更多信息:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=407010

https://bugs.eclipse.org/bugs/show_bug.cgi?id=407010

and here:

和这里:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=409473

https://bugs.eclipse.org/bugs/show_bug.cgi?id=409473

https://bugs.eclipse.org/bugs/show_bug.cgi?id=390889

https://bugs.eclipse.org/bugs/show_bug.cgi?id=390889