Repaso
EspaƱol
Spring, JPA & Java WebFoundationsSPR-39

What is an annotation such as @Override or @Service in Java?

Options

  1. A label (metadata) on code that the compiler or a framework reads (Correct option)
  2. A comment that the compiler and frameworks always ignore
  3. A mandatory import statement placed at the top of the file
  4. A kind of loop that repeats over a list

Answer

A label (metadata) attached to code that the compiler or a framework reads to change how it behaves

Why

Annotations start with @ and sit above classes, methods or fields.

Example: @Override tells the compiler to check that the method really overrides a parent method. @Service tells Spring to create and manage an object of that class.

Spring uses annotations everywhere, so reading them is a core skill: @RestController, @GetMapping, @Autowired, @Transactional.

Remember

Annotation = a label that frameworks read.

Key terms

Practice this question in Repaso