Examples of Java annotations

Use of Java annotations @ h_ 403_ 3@

The use of annotation is very simple. You only need to mark an annotation where annotation is needed, such as annotation on method: @ h_ 403_ 3@

For example, annotate @ h on the class_ 403_ 3@

Therefore, Java built-in annotations can be used directly, but many times we need to define some annotations ourselves. For example, common spring uses a large number of annotations to manage the dependencies between objects. Let's take a look at how to define your own annotation. The following annotation is implemented: inject a string into a class through @ test and a string into a method through @ testmethod@ H_ 403_ 3@

1. Create a test annotation, declare that it will act on the class and keep it until runtime. The default value is default@ H_ 403_ 3@

2. Create testmethod annotation, declare the method to be used and keep it until runtime@ H_ 403_ 3@

3. The test class outputs default and Tomcat method strings after running. Because @ test has no incoming value, it outputs the default value, while @ testmethod outputs the injected string@ H_ 403_ 3@

Thank you for reading, hope to help you, thank you for your support to this site@ H_ 403_ 3@

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>