3

Say we have class

public class Entry<K, V> {
  public Entry(K k,V v) { 
    mKey = k;
    mValue = v;   
  }

  public K getKey() {
    return mKey;
  }

  public V getValue() {
    return mValue;
  }

  ...

}

Then we write an extending class like:

public class ExtendedEntry<K extends SomeSpecificKey, V> extends Entry<K, V>

Then, one class more in the hierarchy:

public class ConcreteEntry<Option extends Something, K extends MoreSpecificKey<Option>, V> extends ExtendedEntry<K, V>

MoreSpecificKey here:

public interface MoreSpecificKey<OptionType extends Something> extends SomeSpecificKey {
    public void doSomething(OptionType option);
}

And I use doSomething() method somewhere in the code of ConcreteEntry.

Then Eclipse compiler says OK and builds code and shows no warnings.

But javac responses:

...ConcreteEntry.java:6 types ...ExtendedEntry and ...ExtendedEntry are incompatible: both define getKey() method, but unrelated return types

When I change (removing generic type) MoreSpecificKey to:

public interface MoreSpecificKey extends SomeSpecificKey {
    public <OptionType extends Something> void doSomething(OptionType option);
}

ConcreteEntry definition now:

public class ConcreteEntry<Option extends Something, K extends MoreSpecificKey, V> extends ExtendedEntry<K, V>

Error in javac is gone, and everything is compiled OK too.

So, what's the reason Eclipse compiles code like this -- is it any compiler parameter defined or different preferences, or differences in compilers. How to handle (fix) this while developing in Eclipse and be sure that it will compile in javac.

shaman.sir
  • 3,198
  • 3
  • 28
  • 36

1 Answers1

4

part of this is already explained in the Question Where does Eclipse find javac to compile a project? - Eclipse uses a different compiler

Community
  • 1
  • 1
kdo
  • 266
  • 1
  • 3
  • Yes, there is an option to monitor the way it builds in both ways with `jconsole` and use `-Dcom.sun.management.jmxremote`. I'll try it now. – shaman.sir Nov 09 '10 at 13:04