Possible Duplicate:
When do you use Java's @Override annotation and why?
My question is very basic why we people use @Override annotation and what is the importance of this annotation?
In Old JDK why it not show as warning, but in latest JDK it required then Why..?
Suppose you have:
You really meant
Foo2.barto overrideFoo.bar, but due to a mistake in the signature, it doesn’t. If you use@Overrideyou can get the compiler to detect the fault. It also indicates to any reading the code that this is overriding an existing method or implementing an interface – advising them about current behaviour and the possible impact of renaming the method.Additionally, your compiler may give you a warning if a method overrides a method without specifying
@Override, which means you can detect if someone has added a method with the same signature to a superclass without you being aware of it – you may not want to be overriding the new method, as your existing method may have different semantics. While@Overridedoesn’t provide a way of “un-overriding” the method, it at least highlights the potential problem.