谁能用简单的英语解释一下下面两段的意思? (摘自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/