java 注释 - 库或语言功能?
Java 注释是否应该被视为一种语言或库功能。我并不是指注释的概念,它显然是一种语言功能,而是特定的注释,例如 @Override 和 @Deprecated?
看起来更清楚的是,仅由第 3 方库支持的注释(例如 Hibernate 注释)显然不是 Java 语言的一部分,但对于内置注释我不太确定。
如果这被认为过于散漫,请随意转到programmers.stackexchange.com
Should Java annotations be considered a language or library feature. I don't mean the very concept of annotations which is obviously a language feature, but specific annotations such as @Override and @Deprecated?
It seems clearer that annotations supported only by 3rd-party libraries (e.g. Hibernate annotations) are clearly not part of the Java language, but for the built-in annotations I'm not so sure.
If this is considered too discursive, feel free to move to programmers.stackexchange.com
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
@Deprecated
和@Override
等注释是语言工具用来强制和/或描述代码行为的库功能。绝对是图书馆的特色。Annotations like
@Deprecated
and@Override
are library features that happen to be used by the language tools to enforce and/or describe code behavior. Definitely library features.注释(在 Java 中)用于将元数据添加到代码中。注解是编写可读且可维护的代码的方式。因此,要编写好的代码,请使用注释,无论它们是 Java 注释还是任何其他第三方注释。
例如,现在想要使 EJB 无状态,您只需添加 @Stateless 注释。
Annotations are used (in Java) for adding meta data to your code. Annotations are the way to write readable and maintainable code. Therefore to write good code use annotations weather they are Java annotations or any other third party.
for e.g. like to make an EJB stateless now you just need to add @Stateless annotation.
我的想法是这样的:
JLS 描述了 Java编程语言。正如您清楚地了解的那样,注释的概念是一种语言功能。另一方面,JLS 没有描述大量标准 Java 库功能,例如 Collections API。
来自 JLS §9.6.1,预定义注释类型< /a>:
沿着这些思路思考,我会说 Java 注释是一个库功能。
Here's how I think about it:
The JLS describes Java the programming language. As you clearly understand, the concept of annotations is a language feature. On the other hand, there are tons of standard Java library features which are not described by the JLS, such as the Collections APIs.
From JLS §9.6.1, Predefined Annotation Types:
Thinking along those lines, then, I'd say that Java annotations are a library feature.