【问题标题】:Compiler difference between IntelliJ and EclipseIntelliJ 和 Eclipse 的编译器区别
【发布时间】:2009-12-01 18:14:47
【问题描述】:

我有一个如下所示的课程。此类在 Eclipse build 20090920-1017 上编译良好:

public class MyScheduledExecutor implements ScheduledExecutorService {

    ...

    public <T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException {
        ...
    }


    public <T> List<Future<T>> invokeAll(Collection<Callable<T>> tasks) throws InterruptedException {
        ...
    }


    public <T> T invokeAny(Collection<Callable<T>> tasks, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
        ...
    }


    public <T> T invokeAny(Collection<Callable<T>> tasks) throws InterruptedException, ExecutionException {
        ...
    }

    ...

}

但是,如果我尝试在 IntelliJ 9 中编译,则会出现编译错误。如果我将所有对&lt;Callable&lt;T&gt;&gt; 的引用替换为&lt;? extends Callable&lt;T&gt;&gt;,它只会在IntelliJ 中编译。例如:

    public <T> T invokeAny(Collection<? extends Callable<T>> tasks) throws InterruptedException, ExecutionException {
        ...
    }

不幸的是,如果我再次尝试在 Eclipse 中重新编译修改后的类,则会出现编译错误。

Name clash: The method invokeAll(Collection<? extends Callable<T>>) of type 
SingleScheduledExecutor has the same erasure as invokeAll(Collection<Callable<T>>) of
type ExecutorService but does not override it

有什么方法可以创建一个实现ScheduledExectorService 的类,该类将在 IntelliJ 和 Eclipse 下编译?两个 IDE 似乎都配置为使用 Java 1.5,这对于我的部署平台是正确的。

【问题讨论】:

    标签: java eclipse intellij-idea


    【解决方案1】:

    在 Java 6 中,ExecutorService 声明了以下方法(例如):

    <T> T invokeAny(Collection<? extends Callable<T>> tasks)
                throws InterruptedException,
                       ExecutionException
    

    但在 Java 5 中,同样的方法在 ExecutorService 中声明如下:

    <T> T invokeAny(Collection<Callable<T>> tasks)
                throws InterruptedException,
                       ExecutionException
    

    我没有安装 Java 5 并且无法使用 Eclipse Java EE Galileo 20090920-1017 重现错误(我在 Ubuntu 下,并且 sun-java5-jdk 已从 Karmic 的存储库中删除,我太懒了手动安装),但实际上,我认为 Eclipse 是对的。

    您确定您在 IntelliJ IDEA 中使用的是 JDK 5(而不是符合 1.5 级别的 JDK 6)吗?

    【讨论】:

    • 这很烦人。我肯定选择了 1.5,但在 Mac OS X Snow Leopard 上,JDK 1.5 实际上是文件系统上 1.6 的符号链接。即使指定 IntelliJ 自己的 1.5 JDK 而不是系统 JDK,最终还是使用系统 1.6 JDK。哈伦普。
    • 为了后代,我能够按照此链接上的说明在 Snow Leopard 10.6.2 上安装 Java 1.5(替换最新版本的 java 1.5,在撰写本文时它是更新 5):@ 987654323@
    • 我理解你的痛苦,看起来苹果应该为这个肮脏的符号链接负责。不能在 Snow Leopard 上安装真正的 JDK 1.5 吗?
    猜你喜欢
    • 2011-03-04
    • 1970-01-01
    • 1970-01-01
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 2018-05-09
    • 2017-01-02
    相关资源
    最近更新 更多