代码之家  ›  专栏  ›  技术社区  ›  emmby

intellij和eclipse之间的编译器差异

  •  1
  • emmby  · 技术社区  · 15 年前

    我有一门课,看起来像是。此类在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 {
            ...
        }
    
        ...
    
    }
    

    但是,如果我尝试在Intellij9中编译,我会得到一个编译错误。只有当我替换对的所有引用时,它才会在intellij中编译。 <Callable<T>> 具有 <? extends Callable<T>> . 例如:

        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,这对于部署平台是正确的。

    1 回复  |  直到 12 年前
        1
  •  8
  •   Arjan Tijms Mike Van    12 年前

    在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 EE Galio 200 90920—1017(我在Ubuntu和Sun-Java5-JDK下被从KARIC的库中删除,我懒得手动安装)错误,但实际上,我认为 日食 是正确的。

    您确定在Intellij思想中使用JDK5(而不是符合1.5级标准的JDK6)吗?