hi, as mentioned in table of content, what is retention actually ?
posted 10 years ago
Thanks for the query. "Retention" is discussed in the chapter on annotations. When creating your own custom annotations, you can specify how long they should be retained (kept around). This retention period can be one of three enum values: RetentionPolicy.SOURCE, RetentionPolicy.CLASS (which is the default), or RetentionPolicy.RUNTIME.
You might use RetentionPolicy.SOURCE if you've created an annotation that only an IDE needs to use. For example, you might have an @Todo annotation that marks sections of code as needing more work. This annotation information gets discarded when the code is compiled.
RetentionPolicy.CLASS means the annotation is stored in the class file, but the VM can choose to discard it at runtime.
RetentionPolicy.RUNTIME means that the annotation sticks around in the class file and is available at runtime. Sun modified the reflection API to allow extracting this annotation information at runtime.