問題描述
Java 中注解的目的是什么?我有一個模糊的想法,認為它們介于注釋和實際代碼之間.它們在運行時會影響程序嗎?
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?
它們的典型用法是什么?
What are their typical usages?
它們是 Java 獨有的嗎?有 C++ 等價物嗎?
Are they unique to Java? Is there a C++ equivalent?
推薦答案
注解主要用于檢查其他代碼的代碼.它們通常用于在運行時修改(即裝飾或包裝)現有類以改變它們的行為.JUnit 和 Hibernate 使用注解來最大限度地減少您自己編寫以使用框架所需的代碼量.
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 對這個概念及其Java 中的含義 在他們的網站上.
Oracle has a good explanation of the concept and its meaning in Java on their site.
這篇關于Java 注釋的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!