dimanche 3 janvier 2021

RetentionPolicy in annotations real life use cases, which "RetentionPolicy" is better to use in what situations

Which "RetentionPolicy" is used in which situations, can you explain this in a more concrete, clear way and in more detail? Can you give some real life use cases related to retentionpolicies? What are the differences between retentionpolicies?

In Oracle Java SE 8 documentation, RetentionPolicy is explained as:

CLASS : Annotations are to be recorded in the class file by the compiler but need not be retained by the VM at run time.

RUNTIME : Annotations are to be recorded in the class file by the compiler and retained by the VM at run time, so they may be read reflectively.

SOURCE : Annotations are to be discarded by the compiler.





Aucun commentaire:

Enregistrer un commentaire