Java语言规范文档的组织说明

1、规范文档表示法说明

原文翻译

Throughout this specification, we refer to classes and interfaces drawn from the Java SE Platform API. Whenever we refer to a class or interface (other than those declared in an example) using a single identifier N, the intended reference is to the class or interface named N in the package java.lang. We use the canonical name (§6.7) for classes or interfaces from packages other than java.lang.
在本规范中,我们引用了从JavaSE平台API中提取的类和接口。每当我们使用单个标识符N引用一个类或接口(示例中声明的除外)时,所要引用的是java.lang包中名为N的类或接口。我们对java.lang以外的包中的类或界面使用规范名称(§6.7)。

A cross-reference within this specification is shown as (§x.y). Occasionally, we refer to concepts in the The Java Virtual Machine Specification, Java SE 22 Edition via cross-references of the form (JVMS §x.y).
本规范中的交叉引用会以(§x.y)的形式展示。偶尔,我们会以(JVMS §x.y)的形式来交叉引用来自Java SE 22版Java虚拟机规范中的概念。

Non-normative text, designed to clarify the normative text of this specification, is given in smaller, indented text.
旨在澄清本规范规范性文本的非规范性文本采用较小的缩进文本。

This is non-normative text. It provides intuition, rationale, advice, examples, etc.
这是非规范性文本。它提供了直觉、理由、建议、例子等。

To shorten the description of some rules, especially those that systematically analyze the constructs of the Java programming language, the customary abbreviation "iff" is used to mean "if and only if".
为了缩短对某些规则的描述,特别是那些系统分析Java编程语言结构的规则,习惯缩写“iff”用于表示“如果且仅当”。

The type system of the Java programming language occasionally relies on the notion of a substitution. The notation [F1:=T1,...,Fn:=Tn] denotes substitution of Fi by Ti for 1 ≤ i ≤ n.
Java编程语言的类型系统偶尔会依赖于替换的概念。符号[F1:=T1,…,Fn:=Tn]表示在1≤i≤n范围内Ti与Fi是可代换的。

总结

1、Java语言的完整类名是包含所在包名的,如日期类完整类名:java.util.Date
2、只有java.lang包下的类可以以独立的类名称出现在源代码中。其他包下的类名称必须以import引入包名或者用完整的携带有包名的类名,方可使用
3、规范中引用其他章节内容采用(§x.y)的形式,引用JVM规范内容章节采用(JVMS §x.y)的形式
4、用于解释规范文档中的特殊词句的文字,用较小字体文本在规范中展现,其解释的内容主要有:直觉、理由、建议、例子
5、文档中也会采用固定的一些缩写来代替一些名词描述,以缩短描述内容
6、文档中会出现符号概念的代换

2、规范文档中使用用的预定义类和接口说明

原文翻译

As noted above, this specification often refers to classes and interfaces of the Java SE Platform API. In particular, some classes and interfaces have a special relationship with the Java programming language. Examples include classes such as Object, Class, ClassLoader, String, and Thread, and the classes and interfaces in the package java.lang.reflect, among others. This specification constrains the behavior of such classes and interfaces, but does not provide a complete specification for them. The reader is referred to the Java SE Platform API documentation.
如上所述,本规范通常引用Java SE平台API的类和接口。特别是,一些类和接口与Java编程语言有着特殊的关系。示例包括Object、Class、ClassLoader、String和Thread等类,以及包java.lang.reflect中的类和接口等。此规范限制了此类类和接口的行为,但没有为它们提供完整的规范。读者可参考Java SE平台API文档。

Consequently, this specification does not describe reflection in any detail. Many linguistic constructs have analogs in the Core Reflection API (java.lang.reflect) and the Language Model API (javax.lang.model), but these are generally not discussed here. For example, when we list the ways in which an object can be created, we generally do not include the ways in which the Core Reflection API can accomplish this. Readers should be aware of these additional mechanisms even though they are not mentioned in the text.
因此,本说明书没有详细描述反射。许多语言构造在核心反射API(java.lang.reflect)和语言模型API(javax.lang.Model)中都有类似的结构,但这里通常不讨论这些结构。例如,当我们列出可以创建对象的方法时,我们通常不包括核心反射API可以实现这一点的方法。读者应该意识到这些额外的机制,即使文本中没有提到它们。

总结

1、本规范使用的SE平台的类和接口属于阉割版的,没有完全体现这些类的所有功能,具体使用时以API文档为准
2、关于反射能够实现的功能本规范也没有完全描述出来,不要迷信本规范,规范没提到的不代表一定不存在

规范文档中关于语言的预览特性的说明

原文翻译

A preview feature is:
预览功能是:

  • a new feature of the Java programming language ("preview language feature"), or
    Java编程语言的新功能(“预览语言功能”),或

  • a new module, package, class, interface, field, method, constructor, or enum constant in the java.* or javax.* namespace ("preview API")
    java.或javax.命名空间中的新模块、包、类、接口、字段、方法、构造函数或enum常量(“预览API”)

that is fully specified, fully implemented, and yet impermanent. It is available in implementations of a given release of the Java SE Platform to provoke developer feedback based on real world use; this may lead to it becoming permanent in a future release of the Java SE Platform.
这是完全指定的、完全实现的,但也是短暂的。它可以在给定版本的Java SE平台的实现中使用,以激发开发人员基于现实世界使用的反馈;这可能导致它在Java SE平台的未来版本中成为永久性的。

Implementations must disable, at both compile time and run time, the preview features defined by a given release of the Java SE Platform, unless the user indicates via the host system, at both compile time and run time, that preview features are to be enabled.
除非用户在编译时和运行时通过主机系统指示要启用预览功能,否则实现必须在编译时或运行时禁用给定版本的Java SE平台定义的预览功能。

The preview features defined by a given release of the Java SE Platform are enumerated in the Java SE Platform Specification for that release. The preview features are specified as follows:
Java SE平台的给定版本定义的预览功能在该版本的Java SE平台规范中列举。预览功能指定如下:

  • Preview language features are specified in standalone documents that indicate changes ("diffs") to The Java® Language Specification for that release. The specifications of preview language features are incorporated into The Java® Language Specification by reference, and made a part thereof, if and only if preview features are enabled at compile time.
    预览语言功能在独立文档中指定,这些文档指示对该版本的Java®语言规范的更改(“diffs”)。如果且仅当在编译时启用了预览功能时,预览语言功能的规范通过引用合并到Java®语言规范中,并成为其中的一部分。

    Java SE 22 defines three preview language features: Implicitly Declared Classes and Instance main Methods; Statements Before super``(...); and String Templates. The standalone documents which specify these preview features are available at the Oracle web site which hosts The Java® Language Specification: https://docs.oracle.com/javase/specs/.
    Java SE 22定义了三个预览语言特性:隐式声明类和实例主方法;语句在超级``(…);之前;和字符串模板。指定这些预览功能的独立文档可在承载Java®语言规范的Oracle网站上获得:
    https://docs.oracle.com/javase/specs/.

  • Preview APIs are specified within the Java SE API Specification for that release.
    预览API是在该版本的Java SE API规范中指定的。

The rules for use of preview language features are as follows:
预览语言功能的使用规则如下:

  • If preview features are disabled, then any source code reference to a preview language feature, or to a class or interface declared using a preview language feature, causes a compile-time error.
    如果预览功能被禁用,则任何对预览语言功能的源代码引用,或对使用预览语言功能声明的类或接口的引用,都会导致编译时错误。

  • If preview features are enabled, then any source code reference to a class or interface declared using a preview language feature causes a preview warning, unless one of the following is true:
    如果启用了预览功能,则对使用预览语言功能声明的类或接口的任何源代码引用都会导致预览警告,除非以下情况之一为真:

    • The reference appears in a declaration that is annotated to suppress preview warnings (§9.6.4.5).
      引用出现在声明中,该声明被注释为禁止预览警告(§9.6.4.5)。

    • The reference appears in an import declaration (§7.5).
      该引用出现在接口申报单中(§7.5)。

    When preview features are enabled, Java compilers are strongly encouraged to give a non-suppressible warning for every source code reference to a preview language feature. Details of this warning are beyond the scope of this specification, but the intent should be to alert programmers to the possibility of code being affected by future changes to preview language features.
    如果启用了预览功能,强烈建议Java编译器对每个引用预览语言功能的源代码发出不可抑制的警告。此警告的详细信息超出了本规范的范围,但其目的应该是提醒程序员,代码可能会受到未来预览语言功能更改的影响。

Some preview APIs are described as reflective by the Java SE Platform Specification, principally in the java.lang.reflect, java.lang.invoke, and javax.lang.model packages. The rule for use of reflective preview APIs is as follows:
Java SE平台规范将一些预览API描述为反射式API,主要在Java.lang.reflect、Java.lang.invoke和javax.lang.model包中。反射式预览API的使用规则如下:

  • Whether preview features are enabled or disabled, any source code reference to a reflective preview API element causes a preview warning, unless one of the following is true:
    无论预览功能是启用还是禁用,对反射预览API元素的任何源代码引用都会导致预览警告,除非以下情况之一为真:

    • The declaration where the reference appears is within the same module as the declaration of the reflective preview API element.
      引用出现的声明与反射预览API元素的声明位于同一模块内。

    • The reference appears in a declaration that is annotated to suppress preview warnings.
      引用出现在一个声明中,该声明被注释为不显示预览警告。

    • The reference appears in an import declaration.
      引用出现在接口声明中。

All preview APIs not described as reflective in the Java SE Platform Specification are normal. The rules for use of normal preview APIs are as follows:
Java SE平台规范中未描述为反射的所有预览API都是正常的。正常预览API的使用规则如下:

  • If preview features are disabled, then any source code reference to a normal preview API element causes a compile-time error, unless:
    如果预览功能被禁用,则任何对普通预览API元素的源代码引用都会导致编译时错误,除非:

    • The declaration where the reference appears is within the same module as the declaration of the normal preview API element.
      引用所在的声明与普通预览API元素的声明位于同一模块内。
  • If preview features are enabled, then any source code reference to a normal preview API element causes a preview warning, unless one of the following is true:
    如果启用了预览功能,则对正常预览API元素的任何源代码引用都会导致预览警告,除非以下情况之一为真:

    • The declaration where the reference appears is within the same module as the declaration of the normal preview API element.
      引用所在的声明与普通预览API元素的声明位于同一模块内。

    • The reference appears in a declaration that is annotated to suppress preview warnings.
      引用出现在一个声明中,该声明被注释为不显示预览警告。

    • The reference appears in an import declaration.
      引用出现在接口声明中。

总结

  • 预览功能分两类
    1、预览语言功能(语言新增的新特性)
    2、预览API(java.或javax.命名空间中的新模块、包、类、接口、字段、方法、构造函数或enum常量)

  • 关于预览功能有如下特点

    1、功能实现是完善可用的
    2、有可能在未来会发生不可预知的变更
    3、目的是为了鼓励开发者使用这些功能并提供反馈以促使在未来成为永久好用的功能
    4、默认情况下预览功能是被禁用的,启用需要开发者明确指明使用预览功能

  • 预览功能在本规范中体现说明

    1、预览语言功能描述在独立的文档中体现。当在编译时启用了预览功能时,预览语言功能的规范才会被引入到Java®语言规范中,并成为其中的一部分,不启用则不会作为语言规范的一部分。
    2、预览API是在该版本的Java SE API规范中指定的

  • 预览语言功能的使用规则
    1、禁用预览功能时,直接的源代码引用或者间接引用了预览语言功能的类和接口,都会导致编译失败。
    2、启用预览功能时使用预览语言功能会触发警告,以下不会触发此警告:

    a.只出现在引入声明中
    b.出现在代码逻辑中并声明了禁止触发警告

    3、建议Java编译器的实现者在实现编译器时对使用了预览语言功能源代码发出不可抑制的警告,向开发者提示使用风险

  • 预览API是使用规则

    • 反射预览API规则(主要在Java.lang.reflect、Java.lang.invoke和javax.lang.model包中)
      1、无论预览功能是启用还是禁用,对反射预览API元素的任何源代码引用都会导致预览警告,以下不会触发此警告:

      a.同一模块内使用
      b.出现在代码逻辑中并声明了禁止触发警告
      c.只出现在引入声明中

    • 正常预览API规则
      1、禁用预览功能时,任何对预览API的使用都会编译失败,除非在同一模块内使用
      2、启用了预览功能,任何对预览API的使用都会触发预览警告,以下情况除外:

      a.声明使用在同一个模块内
      b.声明使用,并在使用时声明禁止触发警告
      c.只出现在引入声明中

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容