Why at runtime is anyone interested in knowing that a method is deprecated? Can some provide me with some examples?
RetentionPolicy. RUNTIME: The annotations annotated using the RUNTIME retention policy are retained during runtime and can be accessed in our program during runtime.
The RetentionPolicy. SOURCE function determines when an annotation is discarded. We apply @Retention as a meta-annotation to other annotations. The @Retention annotation indicates how long the annotated type should be kept in the program's lifecycle.
The RetentionPolicy in Java determines the point at which an annotation should be discarded. @Retention is a meta-annotation that can be applied to other annotations. @Retention indicates how long the annotated type should be kept in the program's lifecycle.
Annotation Type RetentionIndicates how long annotations with the annotated type are to be retained. If no Retention annotation is present on an annotation type declaration, the retention policy defaults to RetentionPolicy.
There are some frameworks and tools that instantiate objects to work with them.
For example, many JavaBean UI editors create instances of the beans and interact with them as the user manipulates the UI they're designing.
Having the @Deprecated annotation available at runtime allows tools such as this to flag deprecated methods, events, properties for the user.
You're assuming that @deprecated is only of interest in the compile phase (IDE, compiler), but its not a stretch to imaging instrumentation scenarios where you require that information.
For example, an IDE can inform you of the number of call sites for a deprecated method, but how would you go about determining the percentage of time your application spends in deprecated methods?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With