Java Language Annotations


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.


  • @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'


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