Search code examples
javaandroidannotations

Why do we need to discard annotations at some point?


I'm currently learning about Android annotation topic. I have read this "A retention policy determines at what point annotation should be discarded." My question is why do Java need to discard an annotation at some point? or for what purpose?

ref: https://www.java2novice.com/java-annotations/retention-policy


Solution

  • Some annotations are just for compile time (so compiler can do bunch of things like generating code (ButterKnife and Dagger) or showing warnings (like DrawableRes), helping auto complete for IDE like IntDef) and won't be used in run time. So they will be discarded.