java 注释 - 库或语言功能?

发布于 2024-12-05 09:13:24 字数 219 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩套路吗 2024-12-12 09:13:25

@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.

小伙你站住 2024-12-12 09:13:25

注释(在 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.

相思碎 2024-12-12 09:13:24

我的想法是这样的:

boolean isLanguageFeature(foo)
{
    return JLS.contains(foo)
}

JLS 描述了 Java编程语言。正如您清楚地了解的那样,注释的概念是一种语言功能。另一方面,JLS 没有描述大量标准 Java 库功能,例如 Collections API。

来自 JLS §9.6.1,预定义注释类型< /a>:

Java 平台的库中预定义了几种注释类型。其中一些预定义注释类型具有特殊语义。这些语义在本节中指定。本节不提供此处包含的预定义注释的完整规范;这就是适当的 API 规范的作用。此处仅指定那些需要 Java 编译器或虚拟机的特殊行为的语义。

沿着这些思路思考,我会说 Java 注释是一个功能。

Here's how I think about it:

boolean isLanguageFeature(foo)
{
    return JLS.contains(foo)
}

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:

Several annotation types are predefined in the libraries of the Java platform. Some of these predefined annotation types have special semantics. These semantics are specified in this section. This section does not provide a complete specification for the predefined annotations contained here in; that is the role of the appropriate API specifications. Only those semantics that require special behavior on the part of the Java compiler or virtual machine are specified here.

Thinking along those lines, then, I'd say that Java annotations are a library feature.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文