JDK 18 新特性概览
JEP 400: UTF-8 by Default
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.
JEP 400: 默认使用UTF-8
将UTF-8指定为标准Java API的默认字符集。通过此更改,依赖于默认字符集的API将在所有实现、操作系统、区域设置和配置中表现一致。
JEP 408: Simple Web Server
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.
JEP 408: 简易Web服务器
提供一个命令行工具,用于启动一个仅服务静态文件的最小Web服务器。该工具不支持CGI或Servlet类的功能。这个工具将对原型设计、临时编码和测试目的非常有用,特别是在教育环境中。
JEP 413: Code Snippets in Java API Documentation
Introduce an @snippet
tag for JavaDoc's Standard Doclet, to simplify the inclusion of example source code in API documentation.
JEP 413: Java API 文档中的代码片段
为 JavaDoc 的标准文档工具引入 @snippet
标签,以简化在 API 文档中包含示例源代码的过程。
JEP 416: Reimplement Core Reflection with Method Handles
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.
JEP 416: 使用方法句柄重新实现核心反射
在 java.lang.invoke
方法句柄的基础上重新实现 java.lang.reflect.Method
、Constructor
和 Field
。将方法句柄作为反射的底层机制将降低 java.lang.reflect
和 java.lang.invoke
API 的维护和开发成本。
JEP 417: Vector API (Third Incubator)
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.
JEP 417: 向量API(第三次孵化)
引入一个API,用于表达向量计算,该API能够在运行时可靠地编译为支持的CPU架构上的最佳向量指令,从而实现优于等效标量计算的性能。
JEP 418: Internet-Address Resolution 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.
JEP 418: 互联网地址解析SPI
定义一个服务提供者接口(SPI)用于主机名和地址解析,以便 java.net.InetAddress
可以使用除平台内置解析器以外的其他解析器。
JEP 419: Foreign Function & Memory API (Second Incubator)
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.
JEP 419: 外部函数与内存API(第二次孵化)
引入一个API,使Java程序能够与Java运行时之外的代码和数据进行互操作。通过高效调用外部函数(即JVM外的代码)和安全访问外部内存(即不由JVM管理的内存),该API使Java程序能够调用本地库并处理本地数据,而无需JNI的脆弱性和危险性。
JEP 420: Pattern Matching for switch (Second Preview)
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.
JEP 420: switch 的模式匹配(第二次预览)
通过为 switch
表达式和语句增强模式匹配以及对模式语言的扩展,提升 Java 编程语言的功能。将模式匹配扩展到 switch
允许对多个模式进行测试,每个模式都有特定的操作,从而可以简洁而安全地表达复杂的数据导向查询。这是 JDK 18 中的一个 预览语言特性。
JEP 421: Deprecate Finalization for Removal
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.
JEP 421: 弃用终结以便移除
在未来的版本中弃用终结以便移除。当前终结仍然默认启用,但可以禁用以便进行早期测试。在未来的版本中,它将默认禁用,并在后续版本中移除。依赖终结的库和应用程序的维护者应考虑迁移到其他资源管理技术,例如 try
-with-resources 语句 和 清理器。