Annotations

  Annotation       ::=  ‘@’ SimpleType {ArgumentExprs}
  ConstrAnnotation ::=  ‘@’ SimpleType ArgumentExprs

Definition

Annotations associate meta-information with definitions. A simple annotation has the form @´c´ or @´c(a_1 , \ldots , a_n)´. Here, ´c´ is a constructor of a class ´C´, which must conform to the class scala.Annotation.

Annotations may apply to definitions, types, or expressions. An annotation of a definition appears in front of that definition. An annotation of a type appears after that type. An annotation of an expression appears after that expression, separated by a colon. More than one annotation clause may apply to an entity. The order in which these annotations are given does not matter.

Examples:

@deprecated("Use D", "1.0") class C { ... } // Class annotation
@transient @volatile var m: Int             // Variable annotation
String @local                               // Type annotation
(e: @unchecked) match { ... }               // Expression annotation

Predefined Annotations

Predefined annotations are found in the scala.annotation package, and also in the scala package.

Scala Compiler Annotations

Deprecation Annotations

Java Platform Annotations

The meaning of other annotation clauses is implementation-dependent. On the Java platform, the following annotations have a standard meaning.

Java Beans Annotations

User-defined Annotations

Other annotations may be interpreted by platform- or application-dependent tools. The class scala.annotation.Annotation is the base class for user-defined annotations. It has two sub-traits:

Host-platform Annotations

The host platform may define its own annotation format. These annotations do not extend any of the classes in the scala.annotation package, but can generally be used in the same way as Scala annotations. The host platform may impose additional restrictions on the expressions which are valid as annotation arguments.