• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java annotation @Retention(value=RUNTIME) confusion

 
Ranch Hand
Posts: 72
MySQL Database AngularJS Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does it mean by @Retention(value=RUNTIME) in annotations?
Does it mean this annotation can be ignored at compile time even if the annotation class doesn't exist?
What if at runtime JVM fails to inject annotation using reflection (considering annotation doesn't exist)?

Found this link:
http://stackoverflow.com/questions/3567413/why-doesnt-a-missing-annotation-cause-a-classnotfoundexception-at-runtime

Please help me understand this concept.
 
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Retention policies specify until when an annotation should be retained.

SOURCE means that the annotation is thrown away after the compiler has compiled it to byte-code. That means that the .class knows nothing about the annotation.
COMPILE means that the annotation is included in the byte-code. You can inspect classes and find the annotation. The annotation is thrown away when you run the JVM.
RUNTIME means that the annotation is available inside the JVM. You can use reflection to find it.

If an annotation doesn't exist, you will never be able to compile the code. This has nothing to do with retention policies.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic