1

Based off of this well loved question I understand that the @Override annotation is a good coding practice so that we know we are actually Overriding the correct method. But, what's the consequence of not doing it, other than coding practice? Is there some underlying thing in Java that needs that annotation there?

I'm asking because I'm generating Java ActiveMQ Message files from XSD files using XJC. But, in order to add "@Override" without doing hand edits I need to use a separate plug-in from what's available from XJC, which in my case is quite difficult knowing the dependencies. The primary goal is to use XJC and my Ant build.xml to regenerate the Java message files at build time without any hand edits.

Community
  • 1
  • 1
Everlight
  • 431
  • 5
  • 18

2 Answers2

7

Java runtime doesn't need it, it is just for reducing coding errors at compile time.

If you are generating code, you probably will be fine without the @Override annotation, since the code is generated and not written by hand (So there are maybe fewer chances at human error at this level, eg. typo).

Still, if you put the @Override method on the generated method, you could catch at compile time if the generated code is bad.

reegnz
  • 837
  • 9
  • 16
1

It has no influence besides being a good practice and highlighting inheritances errors at compile time.

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.SOURCE)
public @interface Override {
}

RetentionPolicy.SOURCE

Benoit Vanalderweireldt
  • 2,925
  • 2
  • 21
  • 31
  • The retention policy only proves it has no effect **after** the compilation. It could do something during compilation (but that, as you've written isn't the case). – fabian Mar 04 '16 at 21:33
  • Do you know of/have an example of how to implement this in XSD? – Everlight Mar 04 '16 at 23:49