TAGS :Viewed: 28 - Published at: a few seconds ago

[ 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 &lt;T&gt; T invokeAny(Collection&lt;? extends Callable&lt;T&gt;&gt; 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&lt;? extends Callable&lt;T&gt;&gt;) of type 
SingleScheduledExecutor has the same erasure as invokeAll(Collection&lt;Callable&lt;T&gt;&gt;) 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.

Answer 1


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)?