Java annotations are supplements and metadata to the Java compiler, they can be added to classes, methods, fields, parameters, and packages. Although they do not affect the code execution, they can change the way a program is treated by the compiler, they can be an alternative to the Java marker interface.
Annotations start with @
Built in annotation
Annotation | Application | Description |
---|---|---|
@Override | Method | Indicates that a method is intended to override a method in a superclass |
@Decprecated | Method, class, field | Marks a method, class, or field as deprecated, single that it should no longer be used |
@SupressWarnings | Method, class, field, local variable, parameter | Instructs the compiler to suppress specific warnings (e.g. unchecked warnings) |
@SafeVarArgs | Final, static, prive method | Suppresses unchecked warnings in a method or constructor with a variable number of arguments |
Custom annotation
You can create your own annotations by using the @interface
keyword.