views:

300

answers:

1

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.

+4  A: 

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

Pascal Thivent
+1 that should be it!
BalusC
Well that's annoying. I definitely have 1.5 selected, but on Mac OS X Snow Leopard, JDK 1.5 is actually a symlink to 1.6 on the filesystem. Even specifying IntelliJ's own 1.5 JDK instead of the system JDK ultimately uses the system 1.6 JDK. Harumph.
Mike
For posterity, I was able to install Java 1.5 on Snow Leopard 10.6.2 by following the instructions at this link (substitute the latest version of java 1.5, as of this writing it's Update 5): http://chxor.chxo.com/post/183013153/installing-java-1-5-on-snow-leopard
Mike
I understand your pain and it looks like Apple is to blame here with this dirty symlink. Can't you install a real JDK 1.5 on Snow Leopard?
Pascal Thivent
Ok forget my comment :)
Pascal Thivent
+1 - very nice, fundamental work by Pascal.
duffymo