Oracle发布Java 22版本
Oracle发布了Java编程语言和虚拟机的第22个版本(JDK 22)。这是自JDK 21以来的第一个非长期支持(LTS)版本,包含12个JEP(JDK Enhancement Proposal),其中Foreign Function & Memory API和Unnamed Variables & Patterns已经完成预览并正式发布。
JDK 22的主要特性
JDK 22的主要特性包括:
- JEP 423: Region Pinning for G1
- JEP 447: Statements before super(...) (Preview)
- JEP 454: Foreign Function & Memory API
- JEP 456: Unnamed Variables & Patterns
- JEP 457: Class-File API (Preview)
- JEP 458: Launch Multi-File Source-Code Programs
- JEP 459: String Templates (Second Preview)
- JEP 460: Vector API (Seventh Incubator)
- JEP 461: Stream Gatherers (Preview)
- JEP 462: Structured Concurrency (Second Preview)
- JEP 463: Implicitly Declared Classes and Instance Main Methods (Second Preview)
- JEP 464: Scoped Values (Second Preview)
Foreign Function & Memory API
JEP 454正式发布了Foreign Function & Memory API。该功能经过两次孵化和三次预览,主要改进包括:
- 引入新的
Enable-Native-Access清单属性,允许可执行JAR中的代码调用受限方法。 - 支持编程方式构建C函数描述符,避免平台特定常量。
- 改进对本地内存中变长数组的支持。
- 支持本地字符串中的多种字符集。
Unnamed Variables and Patterns
JEP 456正式发布了Unnamed Variables & Patterns。该功能允许使用下划线字符表示未命名的模式和变量,例如instanceof Point(_, int y)和var _ = q.remove(),简化了代码编写。
Implicitly Declared Classes and Instance Main Methods
JEP 463是该功能的第二次预览,旨在简化Java初学者编写程序的过程,减少对大型程序语言特性的依赖。该功能源自Brian Goetz的“Paving the on-ramp”博客文章,Gavin Bierman已发布规范草案供社区审查。
JDK 22发布活动
2024年3月19日,Oracle举行了JDK 22线上发布活动,涵盖Java 22新特性、Java社区更新、JavaFX和GraalVM等内容。活动还宣布JavaOne将于2025年回归,庆祝Java诞生30周年。
JDK 23的展望
JDK 23计划于2024年9月发布,目前仅有一个JEP(JEP 455: Primitive Types in Patterns, instanceof, and switch)已确定纳入。其他候选JEP包括:
- JEP 468: Derived Record Creation (Preview)
- JEP 467: Markdown Documentation Comments
- JEP 466: Class-File API (Second Preview)
- JEP 465: String Templates
此外,Vector API和Stream Gatherers可能会进行第二次孵化或预览。
总结
JDK 22带来了多项新特性和改进,特别是Foreign Function & Memory API和Unnamed Variables & Patterns的正式发布。开发者可以期待JDK 23中更多关于模式匹配、记录创建和文档注释的改进。JDK 22现已可从Oracle官网下载。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用。你还可以使用@来通知其他用户。