有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java注释库还是语言功能?

Java注释应该被视为一种语言或库特性吗。很明显,@是指一种特定的注释,而不是一种特定的注释

显然,只有第三方库支持的注释(例如Hibernate注释)显然不是Java语言的一部分,但对于内置注释,我不太确定

如果这被认为过于散漫,请随意转向程序员。斯塔克交换。com


共 (3) 个答案

  1. # 1 楼答案

    注释(在Java中)用于向代码中添加元数据。注释是编写可读和可维护代码的方法。因此,无论注释是Java注释还是任何其他第三方,都要使用注释来编写好的代码

    例如,想让EJB变成无状态,现在只需要添加@stateless注释

  2. # 2 楼答案

    @Deprecated@Override这样的注释是库功能,语言工具使用它们来强制和/或描述代码行为。肯定是图书馆的特色

  3. # 3 楼答案

    我是这样想的:

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

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

    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.

    按照这些思路,我认为Java注释是一种特性