关于注解的说明
谁能用简单的英语解释一下下面两段的意思? (取自 http://www.ibm.com/developerworks/java /library/j-cwt08025.html)
“注释更加灵活 就你如何使用它们而言, 是否注释的选项 信息将包含在课堂中 编译器输出并制作的文件 应用程序在运行时可用 时间”
不确定这些意味着什么。注释可以配置为有选择地更改字节码吗?
虽然注释非常适合 与特定相关的元数据 组件,它们不太适合 具有跨组件的元数据 应用程序。
恕我直言,大多数 Web 应用程序都是跨组件的。作者在这里想表达什么?
Can anyone please explain what the following two paragraphs mean, in simple english? (Taken from 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"
Not sure what these means. Can Annotations be configured to optionally change the bytecode?
While annotations are ideal for
metadata that relates to a particular
component, they are not well suited to
metadata with cross-component
application.
IMHO most web applications would be cross-component ones. What is the author trying to say here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为,这是指 Java5 注释可以被编译器删除,而有些注释可以保留在字节码中 这是由放置在注释类型上的
@Retention
注释控制的,例如,这表明
@Deprecated
注释将出现在字节码中,并且也是可见的反思。java.lang.annotation.RetentionPolicy
定义不同的选项。This, I think, refers to the fact that Java5 annotations can be dropped by the compiler, whereas some can be retained in the bytecode. This is controlled by the
@Retention
annotation that is placed on your annotation type, e.gThis indicates that the
@Deprecated
annotation will be present in the bytecode, and will also be visible to reflection.java.lang.annotation.RetentionPolicy
defines the different options.比 XDoclet 更灵活,因为:
与外部 Xml 相比,注释(如 XDoclet)有一个有趣的功能:
注释存在于代码中,因此它们很自然地应用于定义它们的代码。您不必指定(使用一些复杂的语法)它们适用于哪一段代码。示例:
如果您希望在外部 Xml 文件中具有相同的内容,则必须使用复杂的语法来标识您引用的代码段。这使得它们非常容易应用。
此外,在代码重构(如重命名)的情况下,注释仍然可以正常工作,而必须更改外部 xml 以指向新的类或方法名称。
我不相信在 Web 应用程序中,大多数东西都是跨组件的。
It is more flexible than XDoclet because:
Annotations (like XDoclet) have one interesting feature, as opposed to an external Xml for example :
Annotations live in the code, so it is natural for them to be applied to the code they are defined on. You don't have to specify (using some complex syntax) to what piece of code they apply. Examples:
If you want to have the same in an external Xml file, you have to use a complex syntax to identify the piece of code you refer to. So that makes them very easy to apply.
Also, in case of a code refactoring (like renaming), annotations continue to work just fine, while an external xml would have to be changed to point to the new class or method name.
I don't believe that in a web application, most things are cross-component.