Before talking about the use of annotations, let us first introduce the difference between XML and annotations:
Note: It is a kind of dispersed metadata, closely connected with the source code.
xml: It is a kind of centralized metadata that is not bound to the source code.
This part is mostly used for the development of Java background configuration projects. We know that a few years ago, most server configuration projects were stored in xml files. Spring 2.5 began to be configured based on annotations, thus realizing the function of replacing configuration files.
Comments have four main functions:
1. Generate documentation. Generate javadoc documentation through metadata marked in the code.
2. Compilation check. The compiler checks and verifies through the metadata marked in the code during the compilation process.
3. Dynamic processing at compile time. Metadata marked in the code is dynamically processed at compile time, such as dynamically generating code.
4. Dynamic processing is performed at runtime. Dynamic processing is performed at runtime through the metadata displayed in the code, such as using reflection injection instances.
Collections in Java are mainly divided into four categories:
1. List: ordered, repeatable;
2. Queue: ordered and repeatable;
3. Set: non-repeatable;
4. Map: unordered, with unique keys and non-unique values.
The above is the detailed content of What is the role of Java annotations?. For more information, please follow other related articles on the PHP Chinese website!