-
Enhancement
-
Resolution: Fixed
-
P4
-
5.0, 6
-
rc
-
generic
-
generic
-
Verified
###@###.### 2004-03-04
J2SE Version (please include all output from java -version flag):
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b40)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b40, mixed mode)
Does this problem occur on J2SE 1.3.x or 1.4.x? Yes / No (pick one)
N/A
Operating System Configuration Information (be specific):
Windows 2000 Professional SP2
Bug Description:
Using @Override on a method from an implemented interface causes
compilation to fail. This seems a shame, as it would be particularly
useful when overriding the method with a different return type in an
interface or abstract class - useful because a mistake made in doing
so might not cause a compiler error yet still may not be what the
programmer had intended.
Steps to Reproduce (be specific):
Compile Food.java (below) using -source 1.5. Note that removing the
@Override annotations allows compilation to succeed.
Test program: Food.java
public interface Food {
Food getInstance();
}
interface Cheese extends Food {
@Override Cheese getInstance(); // compilation error
}
class Biscuit implements Food {
@Override public Food getInstance() { return new Biscuit(); } // compilation error
}
abstract class Fruit implements Food {
@Override public abstract Fruit getInstance(); // compilation error
}
class Apple extends Fruit {
@Override public Apple getInstance() { return new Apple(); } // ok
}
Elided java.net submission since compiler fixes are not accepted
for specification issues.
J2SE Version (please include all output from java -version flag):
java version "1.5.0-beta2"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0-beta2-b40)
Java HotSpot(TM) Client VM (build 1.5.0-beta2-b40, mixed mode)
Does this problem occur on J2SE 1.3.x or 1.4.x? Yes / No (pick one)
N/A
Operating System Configuration Information (be specific):
Windows 2000 Professional SP2
Bug Description:
Using @Override on a method from an implemented interface causes
compilation to fail. This seems a shame, as it would be particularly
useful when overriding the method with a different return type in an
interface or abstract class - useful because a mistake made in doing
so might not cause a compiler error yet still may not be what the
programmer had intended.
Steps to Reproduce (be specific):
Compile Food.java (below) using -source 1.5. Note that removing the
@Override annotations allows compilation to succeed.
Test program: Food.java
public interface Food {
Food getInstance();
}
interface Cheese extends Food {
@Override Cheese getInstance(); // compilation error
}
class Biscuit implements Food {
@Override public Food getInstance() { return new Biscuit(); } // compilation error
}
abstract class Fruit implements Food {
@Override public abstract Fruit getInstance(); // compilation error
}
class Apple extends Fruit {
@Override public Apple getInstance() { return new Apple(); } // ok
}
Elided java.net submission since compiler fixes are not accepted
for specification issues.
- relates to
-
JDK-6326485 Compiler does not enforce rule that interfaces may not use @Override
- Closed
-
JDK-6709448 CONFORMANCE:@Override specification and compiler inconsistent 2
- Closed
-
JDK-6409362 A non-abstract method does not override an abstract one
- Closed
-
JDK-6399361 CONFORMANCE: @Override specification and compiler inconsistent
- Closed