Java / Java 21 Coding Standards Interview Questions
What is the purpose of the @Override annotation in Java coding standards?
@Override tells the compiler that a method is intended to override a superclass method or implement an interface method. If the signature does not actually match one being overridden, compilation fails immediately instead of silently creating an unrelated overloaded method.
@Override public String toString() { return "Order[" + id + "]"; }
Coding standards require it on every override, including equals(), hashCode(), and toString(), because a small typo in a method name or parameter type is otherwise a silent bug: the new method just sits alongside the original instead of replacing its behavior.
It also documents intent for the reader - seeing @Override immediately signals that the method's contract is defined elsewhere and should be read alongside the superclass or interface, rather than in isolation.
More Related questions...