Built-in Annotations

What is an Annotation

An annotation (@Something) attaches metadata to code: classes, methods, fields, parameters. It does nothing by itself; the compiler, a build tool or a framework at runtime reads it and acts. Spring's @RestController, JPA's @Entity and JUnit's @Test are all annotations.

AnnotationPurpose
@Overridecompile error if the method does not override anything (catches typos)
@Deprecated(since = "2.0", forRemoval = true)warn users of old APIs
@SuppressWarnings("unchecked")silence a specific compiler warning
@FunctionalInterfaceenforce exactly one abstract method
@SafeVarargspromise a generic varargs method is safe

@Override Saves You

class Product {
    private final String sku;
    Product(String sku) { this.sku = sku; }

    @Override
    public boolean equals(Product other) {   // COMPILE ERROR: method does not override
        return sku.equals(other.sku);        // a method from its superclass
    }                                        // (the parameter must be Object)
}

Tip: Always write @Override. Without it, the wrong signature above compiles silently and HashSet never calls your method.