問題描述
Java 中注解的目的是什么?我有一個(gè)模糊的想法,認(rèn)為它們介于注釋和實(shí)際代碼之間.它們?cè)谶\(yùn)行時(shí)會(huì)影響程序嗎?
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 獨(dú)有的嗎?有 C++ 等價(jià)物嗎?
Are they unique to Java? Is there a C++ equivalent?
推薦答案
注解主要用于檢查其他代碼的代碼.它們通常用于在運(yùn)行時(shí)修改(即裝飾或包裝)現(xiàn)有類以改變它們的行為.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 對(duì)這個(gè)概念及其Java 中的含義 在他們的網(wǎng)站上.
Oracle has a good explanation of the concept and its meaning in Java on their site.
這篇關(guān)于Java 注釋的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!