开发者

Compiler difference between IntelliJ and Eclipse

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 {
        ...
    }

Unfortunat开发者_如何学Cely, 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)?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜