Back in May, I described how we would update the
specification and implementation of @Override.
Unfortunately, I messed up when integrating the changes and the
specification of
@Override
was not updated. The compiler's behavior is changed but the
documentation does not reflect that.
I will make sure to get the documentation fixed in JDK 7 as soon as possible but it is more problematic updating the documentation of JDK 6 because JSR 270 has been finalized. In the meantime, here is what it was supposed to have looked like:
Indicates that a method declaration is intended to override a method declaration in a supertype. If a method is annotated with this annotation type compilers are required to generate an error message unless either of the following conditions hold:
- The method does override or implement a method declared in a supertype.
- The method has a signature that is override-equivalent to that of any public or protected method declared in Object.
In case Bruce is still reading my blog, I just want to make it perfectly clear that Joe had absolutely nothing to do with this snafu.
Posted by Bruce on December 05, 2006 at 08:13 PM PST #
Posted by Eugene Vigdorchik on December 06, 2006 at 03:25 AM PST #
Posted by Peter von der Ahé on December 06, 2006 at 04:59 AM PST #
Posted by Manabu Nakamura on December 07, 2006 at 11:38 PM PST #
interface MyCloneable {
public Object clone();
}
class NewClass implements MyCloneable { }
You get this error: clone() in java.lang.Object cannot implement clone() in MyCloneable; attempting to assign weaker access privileges; was public.
Posted by Peter von der Ahé on December 08, 2006 at 12:38 AM PST #
interface MyCloneable {
public Object clone() throws CloneNotSupportedException;
}
class NewClass implements MyCloneable, Cloneable {
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
class NewClass2 implements Cloneable {
}
class Test {
public static void main(String[] args) throws Exception {
MyCloneable m = new NewClass();
System.out.println(m.clone());
// System.out.println(new NewClass2().clone());
//compile-time error
}
}
Posted by Manabu Nakamura on December 08, 2006 at 03:00 AM PST #
Apologies in advance if I sounded lame...
<CODE> package java.lang; public class Object { //... protected Object clone() { //... } //... } // so this is not correct? public class MyStuff [extends java.lang.Object] { @Override protected Object clone() { //... } } // how about this? public class MyStuff { @Override public Object clone() { //... } } // and this? public class MyStuff { @Override protected MyStuff clone() { //... } } </CODE>
Posted by Alex Lam on December 11, 2006 at 12:57 AM PST #
Ugh, try again...
package java.lang;
public class Object {
//...
protected Object clone() {
//...
}
//...
}
// so this is not correct?
public class MyStuff [extends java.lang.Object] {
@Override
protected Object clone() {
//...
}
}
// how about this?
public class MyStuff {
@Override
public Object clone() {
//...
}
}
// and this?
public class MyStuff {
@Override
protected MyStuff clone() {
//...
}
}
Posted by Alex Lam on December 11, 2006 at 12:59 AM PST #
The second bullet is for methods in interfaces. Also, the docs now say:
unless at least one of the following conditions hold:
instead of
unless either of the following conditions hold:
Posted by Peter von der Ahé on January 04, 2007 at 07:10 AM PST #