Java Annotations - Retention Policy
Almost always i decide to use a custom Annotation in my code for some fancy feature, i forgot to set the RetentionPolicy
, this should be a post note so i probably won’t forget it anymore.
@RetentionPolicy
is an annotation for annotations (inception here), which tells when an Annotation should be disposed.
The options are:
-
RetentionPolicy.SOURCE
, your annotations will be dropped off during compilation and won't be available during your code execution. -
RetentionPolicy.CLASS
, will maintain the annotations after compiling but they won't be available during your code execution (i confess i don't see the point of this option). -
RetentionPolicy.RUNTIME
, your annotation will be maintained and available during execution.
Written by Felipe Brandão
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Notes
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#