java - 关于注解的说明

标签 java xml annotations metadata

谁能用简单的英语解释一下下面两段的意思? (摘自http://www.ibm.com/developerworks/java/library/j-cwt08025.html)

"Annotations are more flexible in terms of how you use them, with options for whether the annotation information is to be included in class files output by the compiler and made available to the application at run time"

不确定这些意味着什么。可以配置注释来选择性地更改字节码吗?

While annotations are ideal for metadata that relates to a particular component, they are not well suited to metadata with cross-component application.

恕我直言,大多数 Web 应用程序都是跨组件的。作者在这里想表达什么?

最佳答案

Annotations are more flexible in terms of how you use them, with options for whether the annotation information is to be included in class files output by the compiler and made available to the application at run time

我认为,这是指 Java5 注释可以被编译器删除,而有些注释可以保留在字节码中。这是由放置在注释类型上的 @Retention 注释控制的,例如

@Documented
@Retention(value=RUNTIME)
public @interface Deprecated

这表明@Deprecated注释将出现在字节码中,并且对反射也是可见的。 java.lang.annotation.RetentionPolicy 定义不同的选项。

关于java - 关于注解的说明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1524058/

相关文章:

Python ElementTree 不喜欢处理指令名称中的冒号

java - Spring通过注解为当前用户传递参数值

java - 由注解界定的有界类型参数

java - CDI @Inject 或普通的旧 java ee 5 注释

java - 我们如何使用字符串进行大小写切换

java - Spring GET/POST 方法缺少 Content-Type

android - 在 Android 中使用渐变环

java - SQLITE UPDATE OR INSERT 语句不想执行

java - 嵌套循环到数学模型中以计算操作次数

java - 如何使用 Maven FindBugs 生成 HTML 报告?