|
Quick Lists
|
|
Bug ID:
|
6399361
|
|
Votes
|
0
|
|
Synopsis
|
CONFORMANCE: @Override specification and compiler inconsistent
|
|
Category
|
java:compiler
|
|
Reported Against
|
|
|
Release Fixed
|
mustang(b86)
|
|
State
|
10-Fix Delivered,
Verified,
bug
|
|
Priority:
|
5-Very Low
|
|
Related Bugs
|
6326485
,
6409362
,
6424261
,
6501053
,
6709448
,
5008260
|
|
Submit Date
|
16-MAR-2006
|
|
Description
|
FULL PRODUCT VERSION :
A DESCRIPTION OF THE PROBLEM :
@Override indicates that a method declaration is intended to not only override but also implement a method declaration in a superclass.
http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.4.3
-----
abstract class C1 {
public void m1() {
}
public abstract void m2();
}
class C2 extends C1 {
@Override
public void m1() {
}
@Override
public void m2() {
}
}
-----
Please revise the documentation (http://download.java.net/jdk6/docs/api/java/lang/Override.html) or the implementation.
The JLS should explain it more strictly, too.
http://java.sun.com/docs/books/jls/third_edition/html/interfaces.html#9.6.1.4
REPRODUCIBILITY :
This bug can be reproduced always.
Posted Date : 2006-03-16 11:55:36.0
|
|
Work Around
|
N/A
|
|
Evaluation
|
The compiler appears to be wrong. However, fixing this might
cause compatibility problems so we should consider if the compiler
should be fixed or if the JLS should be changed.
Posted Date : 2006-03-16 23:14:05.0
Perhaps the documentation of Override is wrong.
The JLS is unclear in this area and should be clarified.
Posted Date : 2006-04-23 01:08:33.0
Actually, the compiler is correct and the specification is correct.
The method C2.m2 overrides the method C1.m2 (and implements it).
See JLS3 8.4.8.1, Overriding (by Instance Method).
However, the specification is very convoluted and confusing.
There are other examples which the compiler does not get right:
public interface Test {
void m();
}
abstract class A implements Test {
// m() is inherited from Test
}
class B extends A {
@Override
public void m() {}
}
Since m is a member of A, class B is overriding a method from a
superclass. The compiler rejects this program.
The best solution to this problem is to change both the compiler
and the specification of @Override:
* Indicates that a method declaration is intended to override a
* method declaration in a supertype. If a method is annotated with
* this annotation type but is not in fact override-equivalent to any
* method declared in a supertype, compilers are required to generate
* an error message.
Posted Date : 2006-05-11 01:57:28.0
See http://blogs.sun.com/ahe?entry=override for an informal
discussion of alternative solutions.
Posted Date : 2006-05-11 04:18:12.0
|
|
Comments
|
Submitted On 17-MAR-2006
manabu
Although I think this is a bug in the current specification, I hope this is regarded as a request for enhancement, too.
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5008260
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6326485
Submitted On 22-JUL-2008
Ragnvald_id2
The @Override is undoubtedly very useful - especially for overriding. The same concept could be useful for implementing as well. This has been solved by changing the meaning of @Override from just “override” to “override, implement or something like that” which is not really a solution but rather a design flaw. Changing the documentation to something completely unreadable is not really a good fix to the problem. The best solution would be to let @Override mean “override” and create a new annotation @Implement to solve the implement case.
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |