Java Language Annotations

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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


Got any Java Language Question?