Annotations
suggest changeVersions
[{“Name”:“Java SE 5”,“GroupName”:null},{“Name”:“Java SE 6”,“GroupName”:null},{“Name”:“Java SE 7”,“GroupName”:null},{“Name”:“Java SE 8”,“GroupName”:null},{“Name”:“Java SE 9 (Early Access)”,“GroupName”:null}]
Introduction
In Java, an annotation is a form of syntactic metadata that can be added to Java source code. It provides data about a program that is not part of the program itself. Annotations have no direct effect on the operation of the code they annotate. Classes, methods, variables, parameters and packages are allowed to be annotated.
Syntax
- @AnnotationName // ‘Marker annotation’ (no parameters)
- @AnnotationName(someValue) // sets parameter with the name ‘value’
- @AnnotationName(param1 = value1) // named parameter
- @AnnotationName(param1 = value1, param2 = value2) // multiple named parameters
- @AnnotationName(param1 = {1, 2, 3}) // named array parameter
- @AnnotationName({value1}) // array with single element as parameter with the name ‘value’
Remarks
Parameter types
Only constant expressions of following types are allowed for parameters, as well as arrays of these types:
String
Class
- primitive types
- Enum types
- Annotation Types
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents