Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Agile Java - what is retention ?

 
Alvin chew
Ranch Hand
Posts: 834
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi, as mentioned in table of content, what is retention actually ?

thank you
 
Jeff Langr
author
Ranch Hand
Posts: 799
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings Alvin,

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.

-Jeff-
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic