In the following code, MoreSpecificHasInfo.getInfo() is not permitted as an override by the Sun Java 5/6 compilers, saying, "types IHasSpecialInfo and AbstractHasInfo are incompatible; both define getInfo(), but with unrelated return types", although it compiles without error under Eclipse 3.4.2. Also, if I replace the abstract implementation of getInfo() with the commented concrete version, it compiles fine everywhere.
I'm wondering which (if any) of the Sun or Eclipse compilers are in line with the Java Language Spec, and if the Sun's compiler is correct, why is this not permitted?
interface IInfo {
}
interface ISpecialInfo extends IInfo {
}
interface IHasInfo {
IInfo getInfo();
}
interface IHasSpecialInfo extends IHasInfo {
ISpecialInfo getInfo();
}
abstract class AbstractHasInfo implements IHasInfo {
public abstract AbstractInfo getInfo();
abstract class AbstractInfo implements IInfo {
}
}
abstract class MoreSpecificHasInfo extends AbstractHasInfo implements IHasSpecialInfo {
@Override
abstract public MoreSpecificInfo getInfo();
// @Override
// public MoreSpecificInfo getInfo() {
// return null;
// }
abstract class MoreSpecificInfo extends AbstractHasInfo.AbstractInfo implements ISpecialInfo {
}
}