Annotation Type Final

Annotation to add the final modifier to classes, methods, constructors, and fields. Using `final` and directly using `@Final` will have the same result. However, the intention is almost never to use `@Final` directly but rather as part of an annotation collector (meta-annotation). If you like the behavior of an existing annotation but would really like a version that also ensured the respective annotated node was final, you can create such an element, e.g.:
 @interface MyCanonical {}

 @MyCanonical class Foo {}
Here, class Foo will be final as well as having all the normal Canonical enhancements.

Similarly, if you wanted to, you could define:

 @AnnotationCollector([Singleton, Final]) @interface MySingleton {}
Classes annotated with @MySingleton would be final as well as have all the Singleton enhancements.

As another example, you could define:

 @AnnotationCollector([NullCheck, Final, AutoFinal]) @interface MyNullCheck {}
Methods annotated with @MyNullCheck would be final (from @Final), would have all parameters marked final (from @AutoFinal), and would have all parameters checked against null (from @NullCheck).

In general, it would be bad style to have an explicit final modifier and a @Final annotation (or more than one @Final annotation), but in that scenario if there is an explicit final or at least one enabled @Final, then the annotated class or member will be final.
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    When disabled, this annotation effectively becomes a no-op.
  • Element Details

    • enabled

      boolean enabled
      When disabled, this annotation effectively becomes a no-op. Typically only used to override an annotation collector already containing an enabled @Final annotation. Care must be taken when disabling final in this way since the annotation collector probably had good reason for enabling final.