Add record patterns and nested deconstruction example (Java 21)

已关闭 适合新手
#114 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

已经有一个关联 PR 被合并了。

  • #141 来自 @piomin —— 已合并

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
技术栈
java
领域
documentation

调研方向

先阅读现有的records包:Person、PersonWithAddress以及相邻的PersonTests,因为新示例是在这些内容的基础上扩展,而不是从头开始。浏览 JEP 440,了解 record 模式语法,尤其是像o instanceof PersonWithAddress(var name, Address(var city, _))这样的嵌套解构。在它们旁边添加instanceof和switch示例,并在PersonTests旁边添加测试,然后在 JDK 21 上运行该模块的测试;完成的标准是示例能够编译,且新增测试与现有测试一起通过。

由索引模型根据 Issue 内容生成。

描述

enhancement

Add an example of record patterns (JEP 440, final in Java 21).

Scope

  • Extend the records package (Person, PersonWithAddress) with instanceof record patterns, e.g. o instanceof PersonWithAddress(var name, Address(var city, _))
  • Show nested deconstruction and use inside switch
  • Add tests next to PersonTests
主要语言
Java
星标
48
派生
9
平均合并
8 分钟
30 天内合并 PR
15

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

piomin/sample-java-new-features 的其他 Issue

查看 piomin/sample-java-new-features 的全部 Issue

相似的 Issue

更多 Java Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。