开发者

compiler errors::Intellij Idea vs Eclipse

开发者 https://www.devze.com 2023-02-10 04:30 出处:网络
Different developers use differnt IDE in my team. One Intellij Idea user wrote code like this public class Bar<A> extends AbstractSet<Bar.Inner> {

Different developers use differnt IDE in my team. One Intellij Idea user wrote code like this

public class Bar<A> extends AbstractSet<Bar.Inner> {  
    class Inner {
    }

    @Override
    public Iterator<Inner> iterator() {
        return null;
    }

    @Override
    public int size() {
        return 0;
    }
}

Other one (eclipse user) said that it compiles only with replacement

 public Iterator<Inner> iterator() {

to

 public Iterator<Bar.Inner> iterator() {

or

 extends AbstractSet<Bar.Inner>

to

 extends AbstractSet<Bar<A>.Inner>
 extends AbstractSet<Bar<?>.Inner>//other variant

What is right compiler's behaviour? Where I can get list of such issues?

additional info

eclipse:

  • version: Helios Service Release 1
  • build: 20100917-0705
  • jdk: 1.6.0_23 (instaled on computer)

idea:

  • version: 10.0.2
  • build: 103.72
  • jdk: 1.6.0_21 (by Help -> About)

UPD It's my fail. Idea开发者_StackOverflow中文版 reports about it but only at application building. But, I think, it's Idea's bug too.


This would seem more likely an underlying JDK version issue than an IDE one - have you checked they're all using identical versions, e.g. JDK 1.6.0_23?


The JDK version you see in about dialog is the java version IDEA is run with. JDK used for compiling is at Project Structure -> Project -> Project SDK.

I've tested your code on IDEA Community 10.0.1 on windows with java 1.6_20, openjdk 1.6.20, and java 1.7.0. All three gave me compiler errors. You can also set your IDEA to use eclipse compiler: Settings -> Compiler -> Java Compiler -> Use compiler: Eclipse. It also gives a compilation error:

Eclipse compiler:

The return type is incompatible with <Test.Inner>.iterator()

Java 7:

Bar is not abstract and does not override abstract method iterator() in AbstractCollection

iterator() in Bar cannot override iterator() in AbstractCollection

method does not override or implement a method from a supertype

Java 6 and OpenJDK 6:

Bar is not abstract and does not override abstract method iterator() in java.util.AbstractCollection

iterator() in Bar cannot override iterator() in java.util.AbstractCollection; attempting to use incompatible return type
found   : java.util.Iterator<Bar<A>.Inner>
required: java.util.Iterator<Bar.Inner>

method does not override or implement a method from a supertype

So it's not an IDEA issue, it's something with the JDK you use to compile.


I'll bet the Eclipse JDK is an IBM variant that's different from Sun.


As duffymo stated before, Eclipse doesn't use JDK from Sun but uses their own compiler (which has better support for continuous compiling and ignoring some errors during execution).

However, the objective of Eclipse's team is to have consistent behavior wit Sun JDK as much as possible. So if you get an error that you think should be fixed, you should report a bug to Eclipse team.

Another behavior like this can be read in my blog.


I had the same error some time ago. Eclipse was buggy here, and the compiler didn't complain while compiling with javac showed errors. I filed a bug a long time ago, but they don't seem to have it in the database anymore.

0

精彩评论

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