Java Annotations

前端 未结 8 1063
天命终不由人
天命终不由人 2020-12-02 05:32

What is the purpose of annotations in Java? I have this fuzzy idea of them as somewhere in between a comment and actual code. Do they affect the program at run time?

8条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-02 05:48

    Annotations are primarily used by code that is inspecting other code. They are often used for modifying (i.e. decorating or wrapping) existing classes at run-time to change their behavior. Frameworks such as JUnit and Hibernate use annotations to minimize the amount of code you need to write yourself to use the frameworks.

    Oracle has a good explanation of the concept and its meaning in Java on their site.

提交回复
热议问题