Comments that act on the code : Check whether the method is an overridden method if it is found that the parent class or the referenced interface does not have the method, a compilation error will be reported.Ĭode demo: package kuang.annotation. Hibernate uses the getDeclaredX() variants of the reflection. Hibernate creates the java objects using a no-args constructor and then populates the fields by using reflection to find and set them too. This product takes data in a database and automatically turns it into Java objects and vice versa. Summary: Annotation is a kind of java code, which can be considered as a type, and it is mainly for the machine to seeĪnnotation format java built-in annotations 1.2.1. For example take frameworks like Hibernate. Compilation check: Through the metadata identified in the code, the compiler can implement basic compilation checks.Code analysis: analyze the code through the metadata identified in the code.If this is for test purposes, you should look at mocking frameworks like jMock and EasyMock. ![]() Of course, you could actually generate a real class with a library like BCEL. Writing documents: Generate documents through the metadata identified in the code You can use after implementing InvocationHandler to handle any method calls.The annotation is to explain to people that this method is an overriding method, but to check the machine (if the method name you rewrite is incorrect will report an error !)Īnnotations and reflections are the bottom layer of many java frameworks, so you must learn them well! To separate annotations from commnets, annotations are for people to see, machines will not execute them, and annotations are mainly for machines to "see" įor example, when rewriting the run() method in multi-threading, there will be an annotation. Notes 1.1, the basic concept of annotationĪnnotation : A code-level description, which is a feature introduced by JDK1.5 and later versions, is at the same level as classes, interfaces, and enumerations it can be declared in packages, classes, fields, methods, local variables, In front of method parameters, etc., it is used to explain and comment on these elements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |