Java runtime annotations and compilation annotations

the difference

What is the difference between runtime annotations and compile-time annotations?

a) The retention phase is different. Run-time annotations are retained until run-time and can be accessed at run-time. While compile-time annotations remain until compile-time, they cannot be accessed at runtime.

b) The principle is different. Run-time annotation is a Java reflection mechanism. Retrofit runtime annotations are only used when needed, and compile-time annotations are passed through APT and AbstractProcessor.

c) Different performance. Run-time annotations have an impact on performance due to the use of Java reflection. Annotations at compile time have no effect on performance. This is why ButterKnife switched from runtime to compile time.

d) Different products. Run-time annotations only need to customize the annotation processor, and no other files will be generated. And compile-time annotation usually produces new Java source files.

 

--------------------- 

Annotation is that Java provides a way and method for elements in a source program to associate any information or any metadata.

Annotation is passive metadata, there will never be active behavior
 

Guess you like

Origin blog.csdn.net/cpcpcp123/article/details/115206778