11.7 Annotations in Java Platform, Standard Edition
In Section 11.1, you learned about annotations as custom modifiers. In the process, you encountered @Override several times. Annotations are only recognized by the compiler and are also only valid on methods.
11.7.1 Places for Annotations
Annotations can be set in declarations of the following elements:
-
Types (i.e., classes, interfaces, enumerations, and other annotation types)
-
Members (i.e., constructors, methods, and class/object variables)
For example, an annotation of a type can be set for the following elements:
-
Variable declarations
-
new keyword
-
Typecasting
-
The implements clause
-
The throws clause for methods
Annotations in type usage are called type annotations ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access