What is the purpose of `@Retention` in a custom annotation?

Java Professional Medium

Java Professional — Medium

What is the purpose of `@Retention` in a custom annotation?

Key points

  • `@Retention` in custom annotations controls the retention policy
  • SOURCE means the annotation is only available in the source code
  • CLASS means the annotation is available in the compiled bytecode
  • RUNTIME means the annotation is available at runtime

Ready to go further?

Related questions