TheDocumentation Index
Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
Use this file to discover all available pages before exploring further.
@Override annotation is a built-in Java marker annotation applied to a method declaration to indicate that the method is intended to override or implement a method declared in a superclass or interface. It functions as a strict compiler directive, triggering compile-time signature verification against the parent type hierarchy.
Technical Specifications
- Package:
java.lang.Override - Target:
@Target(ElementType.METHOD)– It can only be applied to methods. Applying it to classes, fields, or variables results in a compilation error. - Retention:
@Retention(RetentionPolicy.SOURCE)– It is retained only in the source code and is discarded by the compiler. It is not written to the.classfile and is unavailable at runtime via reflection.
Syntax
Compiler Mechanics and Verification Rules
When the Java compiler encounters the@Override annotation, it performs a strict lookup within the type hierarchy. The compilation succeeds only if all the following conditions are met:
- Signature Matching: The compiler searches the direct superclass and all implemented interfaces for a method with an identical name and matching parameter types. The parameter types must match exactly after type erasure.
- Return Type Compatibility: The return type of the annotated method must be identical to, or a subtype of (covariant return type), the return type declared in the overridden method.
- Access Modifiers: The annotated method cannot assign a more restrictive access modifier than the method it overrides (e.g., a
protectedmethod in the superclass cannot be overridden asprivate). - Exception Handling: The annotated method cannot declare any new or broader checked exceptions that are not declared by the overridden method.
method does not override or implement a method from a supertype.
Interface Implementation
Prior to Java 1.6, the@Override annotation was restricted exclusively to overriding methods from a superclass. As of Java 1.6 and later, the compiler specification was updated to allow and verify the @Override annotation on methods that implement a declared method from an interface.
Master Java with Deep Grasping Methodology!Learn More





