Java: Annotations

All about those funny @ things that precede methods

According to this lesson on Java Annotations from the Oracle website (retrieved 2016-06-20):

Annotations, a form of metadata, provide 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.

Annotations have a number of uses, among them:

  • Information for the compiler — Annotations can be used by the compiler to detect errors or suppress warnings.
  • Compile-time and deployment-time processing — Software tools can process annotation information to generate code, XML files, and so forth.
  • Runtime processing — Some annotations are available to be examined at runtime.

Some of the annotations that we commonly see in CMPSC 56 include these that are built into Java 8:

And these that are part of JUnit:

Three pre-defined annotations:

See also, Oracle lesson on pre-defined annotations

FunctionalInterface

The @FunctionalInterface annotation is typically used with Java 8 Lambda Expressions. For more information, see Java 8 Lambda Expressions.