Chapter 1. Introduction第1章 介绍

Table of Contents

1.1. Organization of the Specification规范的组织
1.2. Example Programs示例程序
1.3. Notation记号法
1.4. Relationship to Predefined Classes and Interfaces与预定义类和接口的关系
1.5. Preview Features预览功能
1.6. Feedback反馈
1.7. References参考资料

The Java® programming language is a general-purpose, concurrent, class-based, object-oriented language. Java®编程语言是一种通用的、并发的、基于类的、面向对象的语言。It is designed to be simple enough that many programmers can achieve fluency in the language. 它的设计非常简单,许多程序员都能流利地使用该语言。The Java programming language is related to C and C++ but is organized rather differently, with a number of aspects of C and C++ omitted and a few ideas from other languages included. java编程语言与C和C++相关,但是组织起来却不同,C++和C++的一些方面省略了,并且包括了其他语言的一些思想。It is intended to be a production language, not a research language, and so, as C. A. R. Hoare suggested in his classic paper on language design, the design has avoided including new and untested features.它旨在成为一种生产语言,而不是一种研究语言,因此,正如C.A.R.霍尔在他关于语言设计的经典论文中建议,设计避免包含新的和未经测试的特性。

The Java programming language is strongly and statically typed. Java编程语言是强静态类型的。This specification clearly distinguishes between the compile-time errors that can and must be detected at compile time, and those that occur at run time. 该规范清楚地区分了编译时可能检测到的和必须检测到的编译时错误,以及在运行时发生的编译时错误。Compile time normally consists of translating programs into a machine-independent byte code representation. 编译时通常包括将程序翻译成独立于机器的字节码表示。Run-time activities include loading and linking of the classes needed to execute a program, optional machine code generation and dynamic optimization of the program, and actual program execution.运行时活动包括加载和链接执行程序所需的类、可选机器代码生成和程序动态优化以及实际程序执行。

The Java programming language is a relatively high-level language, in that details of the machine representation are not available through the language. Java编程语言是一种相对高级的语言,因为机器表示的细节无法通过该语言获得。It includes automatic storage management, typically using a garbage collector, to avoid the safety problems of explicit deallocation (as in C's free or C++'s delete). 它包括自动存储管理,通常使用垃圾收集器,以避免显式释放的安全问题(如C的free或C++的delete)。High-performance garbage-collected implementations can have bounded pauses to support systems programming and real-time applications. 高性能垃圾收集实现可以有有限的暂停,以支持系统编程和实时应用程序。The language does not include any unsafe constructs, such as array accesses without index checking, since such unsafe constructs would cause a program to behave in an unspecified way.该语言不包括任何不安全的构造,例如不进行索引检查的数组访问,因为这种不安全的构造会导致程序以未指定的方式运行。

The Java programming language is normally compiled to the bytecode instruction set and binary format defined in The Java Virtual Machine Specification, Java SE 17 Edition.Java编程语言通常编译为字节码指令集和Java虚拟机规范Java SE 17版中定义的二进制格式。

1.1. Organization of the Specification规范的组织

Chapter 2 describes grammars and the notation used to present the lexical and syntactic grammars for the language.第2章描述了语法和表示该语言词汇语法和句法语法的符号。

Chapter 3 describes the lexical structure of the Java programming language, which is based on C and C++. 第3章介绍了基于C和C++的java程序设计语言的词汇结构。The language is written in the Unicode character set. 该语言以Unicode字符集编写。It supports the writing of Unicode characters on systems that support only ASCII.它支持在仅支持ASCII的系统上写入Unicode字符。

Chapter 4 describes types, values, and variables. 第4章描述了类型、值和变量。Types are subdivided into primitive types and reference types.类型细分为基本类型和引用类型。

The primitive types are defined to be the same on all machines and in all implementations, and are various sizes of two's-complement integers, IEEE 754 floating-point numbers, a boolean type, and a Unicode character char type. 原语类型在所有机器和所有实现中都定义为相同的,并且是各种大小的两个补整数、IEEE 754浮点数、boolean类型和Unicode字符char类型。Values of the primitive types do not share state.基元类型的值不共享状态。

Reference types are the class types, the interface types, and the array types. 引用类型包括类类型、接口类型和数组类型。The reference types are implemented by dynamically created objects that are either instances of classes or arrays. 引用类型由动态创建的对象实现,这些对象是类或数组的实例。Many references to each object can exist. 可以存在对每个对象的多个引用。All objects (including arrays) support the methods of the class Object, which is the (single) root of the class hierarchy. 所有对象(包括数组)都支持类Object的方法,类Object是类层次结构的(单个)根。A predefined String class supports Unicode character strings. 预定义的String类支持Unicode字符串。Classes exist for wrapping primitive values inside of objects. 存在用于在对象内部包装基元值的类。In many cases, wrapping and unwrapping is performed automatically by the compiler (in which case, wrapping is called boxing, and unwrapping is called unboxing). 在许多情况下,包装和展开由编译器自动执行(在这种情况下,包装称为装箱,展开称为取消装箱)。Classes and interfaces may be generic, that is, they may be parameterized by reference types. 类和接口可以是泛型的,也就是说,它们可以由引用类型参数化。Parameterized types of such classes and interfaces may then be invoked with specific type arguments.然后,可以使用特定的类型参数调用此类类和接口的参数化类型。

Variables are typed storage locations. 变量是类型化的存储位置。A variable of a primitive type holds a value of that exact primitive type. 基元类型的变量保存该基元类型的值。A variable of a class type can hold a null reference or a reference to an object that is an instance of the named class or any subclass of that class. 类类型的变量可以包含空引用或对作为命名类或该类的任何子类的实例的对象的引用。A variable of an interface type can hold a null reference or a reference to an instance of any class that implements the named interface. 接口类型的变量可以包含null引用或对实现命名接口的任何类的实例的引用。A variable of an array type can hold a null reference or a reference to an array. 数组类型的变量可以包含空引用或数组引用。A variable of class type Object can hold a null reference or a reference to any object, whether class instance or array.类类型Object的变量可以包含空引用或对任何对象的引用,无论是类实例还是数组。

Chapter 5 describes conversions and numeric promotions. 第5章介绍了转换和数字提升。Conversions change the compile-time type and, sometimes, the value of an expression. 转换会更改编译时类型,有时还会更改表达式的值。These conversions include the boxing and unboxing conversions between primitive types and reference types. 这些转换包括基本类型和引用类型之间的装箱和拆箱转换。Numeric promotions are used to convert the operands of a numeric operator to a common type where an operation can be performed. 数字提升用于将数字运算符的操作数转换为可执行操作的通用类型。There are no loopholes in the language; casts on reference types are checked at run time to ensure type safety.语言上没有漏洞;在运行时检查引用类型上的强制转换以确保类型安全。

Chapter 6 describes declarations and names, and how to determine what names mean (that is, which declaration a name denotes). 第6章描述了声明和名称,以及如何确定名称的含义(即名称所表示的声明)。The Java programming language does not require classes and interfaces, or their members, to be declared before they are used. Java编程语言不要求在使用类和接口或其成员之前声明它们。Declaration order is significant only for local variables, local classes, local interfaces, and the order of field initializers in a class or interface. 声明顺序仅对局部变量、局部类、局部接口以及类或接口中字段初始值设定项的顺序有效。Recommended naming conventions that make for more readable programs are described here.这里介绍了推荐的命名约定,这些约定使程序更具可读性。

Chapter 7 describes the structure of a program, which is organized into packages. 第7章描述了一个程序的结构,它被组织成包。The members of a package are classes, interfaces, and subpackages. 包的成员包括类、接口和子包。Packages, and consequently their members, have names in a hierarchical name space; the Internet domain name system can usually be used to form unique package names. 包及其成员在分层名称空间中具有名称;Internet域名系统通常可用于形成唯一的包名。Compilation units contain declarations of the classes and interfaces that are members of a given package, and may import classes and interfaces from other packages to give them short names.编译单元包含作为给定包的成员的类和接口的声明,并且可以从其他包导入类和接口以给它们起短名称。

Packages may be grouped into modules that serve as building blocks in the construction of very large programs. 包可以分组成模块,作为构建大型程序的构建块。The declaration of a module specifies which other modules (and thus packages, and thus classes and interfaces) are required in order to compile and run code in its own packages.模块的声明指定了编译和运行其自身包中的代码所需的其他模块(以及包、类和接口)。

The Java programming language supports limitations on external access to the members of packages, classes, and interfaces. Java编程语言支持对包、类和接口成员的外部访问进行限制。The members of a package may be accessible solely by other members in the same package, or by members in other packages of the same module, or by members of packages in different modules. 包的成员可以仅由同一包中的其他成员访问,或由同一模块的其他包中的成员访问,或由不同模块中的包成员访问。Similar constraints apply to the members of classes and interfaces.类似的约束适用于类和接口的成员。

Chapter 8 describes classes. 第8章描述了类。The members of classes are classes, interfaces, fields (variables) and methods. 类的成员包括类、接口、字段(变量)和方法。Class variables exist once per class. 类变量在每个类中存在一次。Class methods operate without reference to a specific object. 类方法在不引用特定对象的情况下运行。Instance variables are dynamically created in objects that are instances of classes. 实例变量是在作为类实例的对象中动态创建的。Instance methods are invoked on instances of classes; such instances become the current object this during their execution, supporting the object-oriented programming style.在类的实例上调用实例方法;这样的实例在执行期间成为当前对象this,支持面向对象编程风格。

Classes support single inheritance, in which each class has a single superclass. 类支持单一继承,其中每个类都有一个超类。Each class inherits members from its superclass, and ultimately from the class Object. 每个类都从其超类继承成员,并最终从类Object继承成员。Variables of a class type can reference an instance of the named class or any subclass of that class, allowing new classes to be used with existing methods, polymorphically.类类型的变量可以引用命名类的实例或该类的任何子类,从而允许新类以多态方式与现有方法一起使用。

Classes support concurrent programming with synchronized methods. 类支持使用synchronized方法进行并发编程。Methods declare the checked exceptions that can arise from their execution, which allows compile-time checking to ensure that exceptional conditions are handled. 方法声明执行时可能出现的已检查异常,这允许编译时检查以确保异常条件得到处理。Objects can declare a finalize method that will be invoked before the objects are discarded by the garbage collector, allowing the objects to clean up their state.对象可以声明一个finalize方法,该方法将在垃圾收集器丢弃对象之前调用,从而允许对象清除其状态。

For simplicity, the language has neither declaration "headers" separate from the implementation of a class nor separate type and class hierarchies.为简单起见,该语言既没有独立于类实现的声明“头”,也没有独立的类型和类层次结构。

A restricted kind of class, enum classes, supports the definition of small sets of values and their manipulation in a type safe manner. 一种受限制的类,枚举类,支持小型值集的定义及其以类型安全的方式进行操作。Unlike enumerations in other languages, enum constants are objects and may have their own methods.与其他语言中的枚举不同,枚举常量是对象,可能有自己的方法。

Another restricted kind of class, record classes, supports the compact expression of simple objects that serve as aggregates of values.另一种受限制的类,记录类,支持作为值集合的简单对象的紧凑表达式。

Chapter 9 describes interfaces. The members of interfaces are classes, interfaces, constant fields, and methods. 第9章描述了接口。接口的成员包括类、接口、常量字段和方法。Classes that are otherwise unrelated can implement the same interface. 不相关的类可以实现相同的接口。A variable of an interface type can contain a reference to any object that implements the interface.接口类型的变量可以包含对实现接口的任何对象的引用。

Classes and interfaces support multiple inheritance from interfaces. 类和接口支持从接口进行多重继承。A class that implements one or more interfaces may inherit instance methods from both its superclass and its superinterfaces.实现一个或多个接口的类可以从其超类和超接口继承实例方法。

Annotations are metadata that may be applied to declarations in a program, as well as to the uses of types in declarations and expressions. 注释是元数据,可以应用于程序中的声明以及声明和表达式中类型的使用。The form of an annotation is defined by an annotation interface, a specialized kind of interface. 注释的形式由注释接口定义,注释接口是一种特殊的接口。Annotations are not permitted to affect the semantics of programs in the Java programming language in any way. 注释不允许以任何方式影响Java编程语言中程序的语义。However, they provide useful input to various tools.然而,它们为各种工具提供了有用的输入。

Chapter 10 describes arrays. 第10章介绍了数组。Array accesses include bounds checking. 数组访问包括边界检查。Arrays are dynamically created objects and may be assigned to variables of type Object. 数组是动态创建的对象,可以分配给Object类型的变量。The language supports arrays of arrays, rather than multidimensional arrays.该语言支持数组的数组,而不是多维数组。

Chapter 11 describes exceptions, which are nonresuming and fully integrated with the language semantics and concurrency mechanisms. 第11章描述了异常,这些异常是非消耗性的,并且与语言语义和并发机制完全集成。There are three kinds of exceptions: checked exceptions, run-time exceptions, and errors. 有三种异常:检查异常、运行时异常和错误。The compiler ensures that checked exceptions are properly handled by requiring that a method or constructor can result in a checked exception only if the method or constructor declares it. 编译器通过要求方法或构造函数仅在方法或构造函数声明检查异常时才能生成检查异常来确保正确处理检查异常。This provides compile-time checking that exception handlers exist, and aids programming in the large. 这提供了编译时检查异常处理程序是否存在的功能,并有助于大规模编程。Most user-defined exceptions should be checked exceptions. 大多数用户定义的异常都应该被检查为异常。Invalid operations in the program detected by the Java Virtual Machine result in run-time exceptions, such as NullPointerException. Java虚拟机检测到程序中的无效操作会导致运行时异常,例如NullPointerExceptionErrors result from failures detected by the Java Virtual Machine, such as OutOfMemoryError. 错误源于Java虚拟机检测到的故障,例如OutOfMemoryErrorMost simple programs do not try to handle errors.大多数简单的程序不会尝试处理错误。

Chapter 12 describes activities that occur during execution of a program. 第12章描述了程序执行期间发生的活动。A program is normally stored as binary files representing compiled classes and interfaces. 程序通常存储为二进制文件,表示已编译的类和接口。These binary files can be loaded into a Java Virtual Machine, linked to other classes and interfaces, and initialized.这些二进制文件可以加载到Java虚拟机中,链接到其他类和接口,并进行初始化。

After initialization, class methods and class variables may be used. 初始化后,可以使用类方法和类变量。Some classes may be instantiated to create new objects of the class type. 某些类可以实例化以创建类类型的新对象。Objects that are class instances also contain an instance of each superclass of the class, and object creation involves recursive creation of these superclass instances.作为类实例的对象还包含类的每个超类的实例,对象创建涉及这些超类实例的递归创建。

When an object is no longer referenced, it may be reclaimed by the garbage collector. 当对象不再被引用时,垃圾收集器可能会回收该对象。If an object declares a finalizer, the finalizer is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. 如果对象声明终结器,则在回收对象之前执行终结器,以便给对象最后一次机会清理否则不会释放的资源。When a class is no longer needed, it may be unloaded.当不再需要某个类时,可以将其卸载。

Chapter 13 describes binary compatibility, specifying the impact of changes to classes and interfaces on other classes and interfaces that use the changed classes and interfaces but have not been recompiled. 第13章描述了二进制兼容性,详细说明了类和接口的更改对使用更改的类和接口但尚未重新编译的其他类和接口的影响。These considerations are of interest to developers of classes and interfaces that are to be widely distributed, in a continuing series of versions, often through the Internet. 这些注意事项对于类和接口的开发人员很感兴趣,这些类和接口将以一系列连续的版本(通常通过Internet)广泛分发。Good program development environments automatically recompile dependent code whenever a class or interface is changed, so most programmers need not be concerned about these details.好的程序开发环境会在类或接口更改时自动重新编译依赖的代码,所以大多数程序员不必关心这些细节。

Chapter 14 describes blocks and statements, which are based on C and C++. 第14章描述了基于C和C++的块和语句。The language has no goto statement, but includes labeled break and continue statements. 该语言没有goto语句,但包含带标签的breakcontinue语句。Unlike C, the Java programming language requires boolean (or Boolean) expressions in control-flow statements, and does not convert types to boolean implicitly (except through unboxing), in the hope of catching more errors at compile time. 与C不同,Java编程语言在控制流语句中需要boolean(或Boolean)表达式,并且不会隐式地将类型转换为boolean(除非通过拆箱),以期在编译时捕获更多错误。A synchronized statement provides basic object-level monitor locking. synchronized语句提供基本的对象级监视器锁定。A try statement can include catch and finally clauses to protect against non-local control transfers. try语句可以包含catch子句和finally子句,以防止非本地控制传输。Chapter 14 also describes patterns, which are used within statements (and expressions) to conditionally declare and initialize local variables.第14章还描述了模式,这些模式在语句(和表达式)中用于有条件地声明和初始化局部变量。

Chapter 15 describes expressions. 第15章描述了表达式。This document fully specifies the (apparent) order of evaluation of expressions, for increased determinism and portability. 为了增强确定性和可移植性,本文档充分规定了表达式求值的(明显的)顺序。Overloaded methods and constructors are resolved at compile time by picking the most specific method or constructor from those which are applicable.重载方法和构造函数在编译时通过从适用的方法或构造函数中选择最具体的方法或构造函数来解决。

Chapter 16 describes the precise way in which the language ensures that local variables are definitely set before use. 第16章描述了该语言确保在使用前明确设置局部变量的精确方式。While all other variables are automatically initialized to a default value, the Java programming language does not automatically initialize local variables in order to avoid masking programming errors.当所有其他变量自动初始化为默认值时,Java编程语言不会自动初始化局部变量以避免掩盖编程错误。

Chapter 17 describes the semantics of threads and locks, which are based on the monitor-based concurrency originally introduced with the Mesa programming language. 第17章描述了线程和锁的语义,这些线程和锁基于Mesa编程语言最初引入的基于监视器的并发性。The Java programming language specifies a memory model for shared-memory multiprocessors that supports high-performance implementations.Java编程语言为支持高性能实现的共享内存多处理器指定了一个内存模型。

Chapter 18 describes a variety of type inference algorithms used to test applicability of generic methods and to infer types in a generic method invocation.第18章描述了用于测试泛型方法的适用性和在泛型方法调用中推断类型的各种类型推断算法。

Chapter 19 presents a syntactic grammar for the language.第19章介绍了该语言的句法语法。

1.2. Example Programs示例程序

Most of the example programs given in the text are ready to be executed and are similar in form to:本文中给出的大多数示例程序都已准备好执行,其形式类似于:

class Test {
  public static void main(String[] args) {
    for (int i = 0; i < args.length; i++)
      System.out.print(i == 0 ? args[i] : " " + args[i]);
    System.out.println();
  }
}

On a machine with the Oracle JDK installed, this class, stored in the file Test.java, can be compiled and executed by giving the commands:在安装了Oracle JDK的计算机上,存储在Test.java文件中的此类可以通过以下命令进行编译和执行:

javac Test.java
java Test Hello, world.

producing the output:产生输出:

Hello, world.

1.3. Notation记号法

Throughout this specification we refer to classes and interfaces drawn from the Java SE Platform API. 在本规范中,我们指的是从JavaSE平台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. 每当我们使用单个标识符N引用类或接口(示例中声明的类或接口除外),预期的引用就是包java.lang中名为N的类或接口。We use the canonical name (6.7) for classes or interfaces from packages other than java.lang.我们对java.lang以外的包中的类或接口使用规范名称(6.7)。

Non-normative information, designed to clarify the specification, is given in smaller, indented text.旨在澄清规范的非规范性信息以较小的缩进文本给出。

This is non-normative information. 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. Java编程语言的类型系统有时依赖于替换的概念。The notation [F1:=T1,...,Fn:=Tn] denotes substitution of Fi by Ti for 1 i n.记号法[F1:=T1,...,Fn:=Tn]表示Fi by Ti for 1 i n的替换。

1.4. Relationship to Predefined Classes and Interfaces与预定义类和接口的关系

As noted above, this specification often refers to classes and interfaces of the Java SE Platform API. 如上所述,该规范通常涉及JavaSE平台API的类和接口。In particular, some classes and interfaces have a special relationship with the Java programming language. 特别是,一些类和接口与Java编程语言有着特殊的关系。Examples include classes such as Object, Class, ClassLoader, String, and Thread, and the classes and interfaces in the package java.lang.reflect, among others. 除此之外,示例包括ObjectClassClassLoaderStringThread,以及包java.lang.reflect中的类和接口。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文档》。

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. 许多语言结构在核心反射API(java.lang.reflect)和语言模型API(javax.lang.model)中都有类似的结构,但这里通常不讨论这些结构。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. 例如,当我们列出创建对象的方式时,通常不包括核心反射API可以实现这一点的方式。Readers should be aware of these additional mechanisms even though they are not mentioned in the text.读者应了解这些附加机制,即使文本中未提及。

1.5. Preview Features预览功能

A preview feature is:预览功能包括:

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

  • a new module, package, class, interface, field, method, constructor, or enum constant in the java.* or javax.* namespace ("preview API")java.*javax.*命名空间(“预览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.它可以在给定版本的JavaSE平台的实现中使用,以根据实际使用情况激发开发人员的反馈;这可能会导致它在JavaSE平台的未来版本中成为永久性的。

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. 给定版本的JavaSE平台定义的预览功能在该版本的JavaSE平台规范中列举。The preview features are specified as follows:预览功能指定如下:

  • Preview language features are specified in standalone documents that indicate changes ("diffs") to The Java® Language Specification for that release. 预览语言功能在独立文档中指定,这些文档指示《Java®语言规范》的该版本的更改(“差异”)。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®语言规范》,并将其作为其一部分。。

    Java SE 17 defines one preview language feature:Java SE 17定义了一种预览语言功能: Pattern Matching for switch. 针对switch的模式匹配The standalone document which specifies this preview feature is available at the Oracle web site which hosts The Java® Language Specification:指定此预览功能的独立文档可在托管《Java®语言规范》的Oracle网站上找到: https://docs.oracle.com/javase/specs/

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

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. 启用预览功能后,强烈建议Java编译器对预览语言功能的每个源代码引用发出不可抑制的警告。Details of this warning are beyond the scope of The Java® Language 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. Java SE平台规范主要在java.lang.reflectjava.lang.invokejavax.lang.model包中将一些预览API描述为反射The rule for use of reflective preview APIs is as follows:反射预览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. Java SE平台规范中未描述为反射的所有预览API都是常规The rules for use of normal preview APIs are as follows:普通预览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.6. Feedback反馈

Readers are invited to report technical errors and ambiguities in The Java® Language Specification to jls-jvms-spec-comments@openjdk.java.net.欢迎读者向jls-jvms-spec-comments@openjdk.java.net报告《Java®语言规范文档》中的技术错误和歧义。

Questions concerning the behavior of javac (the reference compiler for the Java programming language), and in particular its conformance to this specification, may be sent to compiler-dev@openjdk.java.net.有关javac(Java编程语言的参考编译器)行为的问题,特别是其与本规范的一致性,可以发送给compiler-dev@openjdk.java.net

1.7. References参考资料

Bibliography参考文献

Apple Computer. Dylan Reference Manual. Apple Computer Inc., Cupertino, California. September 29, 1995.

Bobrow, Daniel G., Linda G. DeMichiel, Richard P. Gabriel, Sonya E. Keene, Gregor Kiczales, and David A. Moon. Common Lisp Object System Specification, X3J13 Document 88-002R, June 1988; appears as Chapter 28 of Steele, Guy. Common Lisp: The Language, 2nd ed. Digital Press, 1990, ISBN 1-55558-041-6, 770-864.

Ellis, Margaret A., and Bjarne Stroustrup. The Annotated C++ Reference Manual. Addison-Wesley, Reading, Massachusetts, 1990, reprinted with corrections October 1992, ISBN 0-201-51459-1.

Goldberg, Adele and Robson, David. Smalltalk-80: The Language. Addison-Wesley, Reading, Massachusetts, 1989, ISBN 0-201-13688-0.

Harbison, Samuel. Modula-3. Prentice Hall, Englewood Cliffs, New Jersey, 1992, ISBN 0-13-596396.

Hoare, C. A. R. Hints on Programming Language Design. Stanford University Computer Science Department Technical Report No. CS-73-403, December 1973. Reprinted in SIGACT/SIGPLAN Symposium on Principles of Programming Languages. Association for Computing Machinery, New York, October 1973.

IEEE. IEEE Standard for Floating-Point Arithmetic. IEEE Std 754-2019 (Revision of IEEE 754-2008). July 2019, ISBN 978-1-5044-5924-2.

Kernighan, Brian W., and Dennis M. Ritchie. The C Programming Language, 2nd ed. Prentice Hall, Englewood Cliffs, New Jersey, 1988, ISBN 0-13-110362-8.

Madsen, Ole Lehrmann, Birger Møller-Pedersen, and Kristen Nygaard. Object-Oriented Programming in the Beta Programming Language. Addison-Wesley, Reading, Massachusetts, 1993, ISBN 0-201-62430-3.

Mitchell, James G., William Maybury, and Richard Sweet. The Mesa Programming Language, Version 5.0. Xerox PARC, Palo Alto, California, CSL 79-3, April 1979.

Stroustrup, Bjarne. The C++ Progamming Language, 2nd ed. Addison-Wesley, Reading, Massachusetts, 1991, reprinted with corrections January 1994, ISBN 0-201-53992-6.

Unicode Consortium, The. The Unicode Standard, Version 13.0. Mountain View, California, 2020, ISBN 978-1-936213-26-9.