The following code is MoreSpecificHasInfo.getInfo()not permitted as overrides by Sun Java 5/6 compilers, saying " types IHasSpecialInfo and AbstractHasInfo are incompatible; both define getInfo(), but with unrelated return types", although it compiles without errors in Eclipse 3.4.2. Also, if I replace the abstract implementation getInfo()with a commented-out specific version, it compiles everywhere.
I am wondering which (if any) Sun or Eclipse compilers comply with the Java Language Spec , and if the Sun compiler is correct, why is this not allowed?
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();
abstract class MoreSpecificInfo extends AbstractHasInfo.AbstractInfo implements ISpecialInfo {
}
}
source
share