IntelliJ和Eclipse之间的编译器区别 [英] Compiler difference between IntelliJ and Eclipse

查看:248
本文介绍了IntelliJ和Eclipse之间的编译器区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似如下的类。这个类在Eclipse build 20090920-1017上编译好:

  public class MyScheduledExecutor implements ScheduledExecutorService {

。 ..

public< T>列表与LT;未来< T>> invokeAll(集合< Callable&T>任务,长时间超时,TimeUnit单位)throws InterruptedException {
...
}


public< T>列表与LT;未来< T>> invokeAll(Collection< Callable&T;>任务)throws InterruptedException {
...
}


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


公共< T> T invokeAny(Collection< Callable&T;>任务)抛出InterruptedException,ExecutionException {
...
}

...

}

但是,如果我尝试在IntelliJ 9中编译,我会收到一个编译错误。如果我将所有引用替换为< Callable< T> <?扩展Callable< T> 。例如:

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

不幸的是,如果我再次尝试在Eclipse中编译修改后的类,我会收到一个编译错误。

 名称冲突:类型为
的方法invokeAll(Collection<?extends Callable< T>)SingleScheduledExecutor具有与invokeAll(Collection< Callable< T>) b $ b类型ExecutorService但不覆盖它

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

解决方案

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

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

但是在Java 5中,相同的方法在 ExecutorService

 < T> T invokeAny(Collection< Callable&T;>>任务)
throws InterruptedException,
ExecutionException


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



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


I have a class that looks like the following. This class compiles fine on 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 {
        ...
    }

    ...

}

However, if I try to compile in IntelliJ 9, I get a compilation error. It will only compile in IntelliJ if I replace all references to <Callable<T>> with <? extends Callable<T>>. For example:

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

Unfortunately, if I then try to compile the modified class back in Eclipse again, I get a compilation error.

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

Is there any way I can create a class that implements ScheduledExectorService that will compile under both IntelliJ and Eclipse? Both IDEs appear to be configured to use Java 1.5, which is correct for my deployment platform.

解决方案

In Java 6, ExecutorService declares the following method (for example):

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

But in Java 5, the same method is declared like this in ExecutorService:

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

I don't have Java 5 installed and can't reproduce the error with Eclipse Java EE Galileo 20090920-1017 (I'm under Ubuntu and sun-java5-jdk has been removed from Karmic's repositories and I'm too lazy to install it manually) but, actually, I think that Eclipse is right.

Are you sure you are using a JDK 5 in IntelliJ IDEA (and not a JDK 6 with 1.5 level compliance)?

这篇关于IntelliJ和Eclipse之间的编译器区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆