咸鱼

咸鱼是以盐腌渍后,晒干的鱼

0%

JDK 18 新特性

2022年03月22 JDK 18 发布,是 短期维护版本。

新特性: http://openjdk.java.net/projects/jdk/18/

Features

代号 更新
400: UTF-8 by Default
408: Simple Web Server
413: Code Snippets in Java API Documentation
416: Reimplement Core Reflection with Method Handles
417: Vector API (Third Incubator)
418: Internet-Address Resolution SPI
419: Foreign Function & Memory API (Second Incubator)
420: Pattern Matching for switch (Second Preview)
421: Deprecate Finalization for Removal

400: 默认编码为 UTF-8

Specify UTF-8 as the default charset of the standard Java APIs. With this change, APIs that depend upon the default charset will behave consistently across all implementations, operating systems, locales, and configurations.

将 UTF-8 指定为标准 Java API 的默认字符集。通过此更改,依赖于默认字符集的 API 将在所有实现、操作系统、语言环境和配置中保持一致。

408: 简易 HTTP 服务器

Provide a command-line tool to start a minimal web server that serves static files only. No CGI or servlet-like functionality is available. This tool will be useful for prototyping, ad-hoc coding, and testing purposes, particularly in educational contexts.

提供一个命令行工具来启动一个只提供静态文件的最小web服务器。没有可用的CGI或类似servlet的功能。这个工具对于原型设计、特别编码和测试非常有用,特别是在教育环境中。

413: Java API 文档中的代码片段

Introduce an @snippet tag for JavaDoc’s Standard Doclet, to simplify the inclusion of example source code in API documentation.

为 JavaDoc 的 Standard Doclet 引入一个 @snippet 标签,以简化 API 文档中的示例源代码。

416: 用方法句柄(Method Handles)重新实现 Java 核心反射

Reimplement java.lang.reflect.Method, Constructor, and Field on top of java.lang.invoke method handles. Making method handles the underlying mechanism for reflection will reduce the maintenance and development cost of both the java.lang.reflect and java.lang.invoke APIs.

java.lang.invoke 方法句柄的基础上重新实现 java.lang.reflect.MethodConstructorField。让方法句柄成为反射的底层机制将减少 java.lang.reflectjava.lang.invoke API 的维护和开发成本。

417: Vector API (第三次进行孵化)

Introduce an API to express vector computations that reliably compile at runtime to optimal vector instructions on supported CPU architectures, thus achieving performance superior to equivalent scalar computations.

引入一个 API 来表达在运行时能够可靠编译的向量计算,在支持的 CPU 架构上优化向量指令,从而实现优于标量计算的性能。

418: 互联网地址解析 SPI

Define a service-provider interface (SPI) for host name and address resolution, so that java.net.InetAddress can make use of resolvers other than the platform’s built-in resolver.

定义一个用于主机名称和地址解析的服务供给接口(SPI),以便 java.net.InetAddress 可以使用平台内置解析器以外的解析器。

419: 外部函数和内存 API(第二次进行孵化)

Introduce an API by which Java programs can interoperate with code and data outside of the Java runtime. By efficiently invoking foreign functions (i.e., code outside the JVM), and by safely accessing foreign memory (i.e., memory not managed by the JVM), the API enables Java programs to call native libraries and process native data without the brittleness and danger of JNI.

引入一个 API,通过它,Java 程序可以与 Java 运行时之外的代码和数据进行互操作。通过有效地调用外部函数,以及安全地访问外部内存,该 API 使 Java 程序能够调用本地库并处理本地数据,而没有 JNI 的脆弱性和危险。

420: Switch 模式匹配(第二次进行预览)

Enhance the Java programming language with pattern matching for switch expressions and statements, along with extensions to the language of patterns. Extending pattern matching to switch allows an expression to be tested against a number of patterns, each with a specific action, so that complex data-oriented queries can be expressed concisely and safely. This is a preview language feature in JDK 18.

switch 表达式和语句的模式匹配,以及对模式语言的扩展来增强 Java 编程语言。将模式匹配扩展到 switch 中,允许针对一些模式测试表达式,这样就可以简明而安全地表达复杂的面向数据的查询。这是 JDK 18 中的一个预览的语言功能。

421: 弃用 Finalization,以便在未来删除

Deprecate finalization for removal in a future release. Finalization remains enabled by default for now, but can be disabled to facilitate early testing. In a future release it will be disabled by default, and in a later release it will be removed. Maintainers of libraries and applications that rely upon finalization should consider migrating to other resource management techniques such as the try-with-resources statement and cleaners.

弃用 Finalization,以便在未来的版本中删除它。目前 Finalization 仍然是默认启用的,但可以禁用它以便进行早期测试。在之后的版本中,它将率先被默认禁用,并在未来的版本中将其彻底删除。依赖于 Finalization 的库和应用程序的维护者应该考虑迁移到其他资源管理技术,如 try-with-resources 语句。