Java注解 [英] Java Annotations
问题描述
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 表示.
这篇关于Java注解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!