0

I'm curious as to why we have the @Overrides annotation, but there is not a similar idiom for interfaces (such as @Implements or @Implementation). It seems like it'd be a useful feature, as you could require the interface you are implementing to be a value of the annotation.

Was this a conscious decision or just an overlooked one?

I found this question, but it doesn't seem to discuss why there wasn't a separate annotation created.

Community
  • 1
  • 1
Scott
  • 9,458
  • 7
  • 54
  • 81
  • Probably because it's not that big of a deal. `@Override` is sufficient. I guess you could write your own. – Dave Newton Nov 30 '11 at 14:57
  • I was thinking about this as well, but that depends on how the compiler is implemented. If you created your own annotation that extended @Override, would the compiler check for it as well? – Mike Yockey Nov 30 '11 at 15:05
  • I think its because Java tends to be a minimalist language and every feature you add could break backward compatibility. – Peter Lawrey Nov 30 '11 at 15:11

3 Answers3

4

In most cases you don't need such an annotation, because if you don't implement the interface you will receive a compile-time error. The only case is if the class is abstract. There it can be useful. But then again you have the @Override, so a new annotation is probably useless.

Petar Minchev
  • 46,889
  • 11
  • 103
  • 119
  • And if you use @Override on an implemented interface method, you will get a compile error if that method disappears from the interface (which could be an indicator that you need to change your implementation). – sarumont Nov 30 '11 at 19:47
0

I think when you are implementing an interface (e.g. public class AClass implements AInterface), you are using that keyword implements which is enough info to let know that even if you are using @Override, the method is actually an implementation of an abstract method.

Bhesh Gurung
  • 50,430
  • 22
  • 93
  • 142
0

The @Override annotation is merely a marker for the compiler. It exists so that the compiler can generate warnings where the developer's intentions are perhaps confused. The javadoc reads as follows:

Indicates that a method declaration is intended to override a method declaration in a superclass. If a method is annotated with this annotation type but does not override a superclass method, compilers are required to generate an error message.

Any @Implements annotation would probably only provide the same function, so its utility would be limited to the compiler.

Mike Yockey
  • 4,565
  • 22
  • 41