Skip to content

Commit 0b0ce3a

Browse files
CopilotCopilot
andcommitted
Add zh-CN translations for language category (22 files)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 732a22a commit 0b0ce3a

22 files changed

+396
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 紧凑规范构造函数
3+
oldApproach: 显式构造函数验证
4+
modernApproach: 紧凑构造函数
5+
summary: "无需重复参数列表即可验证和规范化 record 字段。"
6+
explanation: "record 可以声明一个省略参数列表的紧凑规范构造函数。编译器在函数体执行后自动将所有参数赋值给对应字段。"
7+
whyModernWins:
8+
- icon: ✂️
9+
title: 减少重复
10+
desc: "无需重复参数列表或手动赋值每个字段。"
11+
- icon: 🛡️
12+
title: 验证
13+
desc: "非常适合 null 检查、范围验证和防御性复制。"
14+
- icon: 📖
15+
title: 意图更清晰
16+
desc: "紧凑语法强调验证逻辑,而非样板代码。"
17+
support:
18+
description: 自 JDK 16 起广泛可用(2021 年 3 月)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 紧凑源文件
3+
oldApproach: 主类样板
4+
modernApproach: void main()
5+
summary: "无需类声明或 public static void main 即可编写完整程序。"
6+
explanation: "紧凑源文件去除了类声明和 public static void main 签名的仪式感。顶层的 void main() 足以运行一个程序。"
7+
whyModernWins:
8+
- icon: 🚀
9+
title: 零仪式
10+
desc: "无需 class、无需 public static void main、无需 String[] args。"
11+
- icon: 🎓
12+
title: 对初学者友好
13+
desc: "新程序员从第一行就能编写有用的代码。"
14+
- icon: 📝
15+
title: 脚本风格
16+
desc: "非常适合快速原型、脚本和示例。"
17+
support:
18+
description: 在 JDK 25 LTS 中正式发布(JEP 512,2025 年 9 月)。
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 接口默认方法
3+
oldApproach: 用抽象类共享行为
4+
modernApproach: 接口上的默认方法
5+
summary: "直接在接口中添加方法实现,支持行为的多重继承。"
6+
explanation: "Java 8 之前,跨不相关类共享行为需要抽象基类,这限制了灵活性。默认方法允许接口在不破坏现有实现的情况下进行演进。"
7+
whyModernWins:
8+
- icon: 🔀
9+
title: 多重继承
10+
desc: "类可以实现多个带有默认方法的接口,不像单继承的抽象类那样受限。"
11+
- icon: 📦
12+
title: API 演进
13+
desc: "向接口添加新方法而不破坏现有实现。"
14+
- icon: 🧩
15+
title: 可组合行为
16+
desc: "自由混合和匹配来自多个接口的功能。"
17+
support:
18+
description: 自 JDK 8 起可用(2014 年 3 月)。
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 匿名类的菱形运算符
3+
oldApproach: 重复类型参数
4+
modernApproach: 菱形运算符 <>
5+
summary: "菱形运算符现在也适用于匿名类。"
6+
explanation: "Java 7 引入了 <> 但不适用于匿名内部类。Java 9 解除了这一限制,使菱形运算符可以在任何地方使用。"
7+
whyModernWins:
8+
- icon: 📏
9+
title: 一致的规则
10+
desc: "菱形运算符无处不在——构造函数和匿名类均适用。"
11+
- icon: 🧹
12+
title: 减少冗余
13+
desc: "类型参数在左侧声明一次,不再重复。"
14+
- icon: 🔧
15+
title: DRY 原则
16+
desc: "编译器已经知道类型——为什么要写两遍?"
17+
support:
18+
description: 匿名类的菱形运算符自 JDK 9 起可用(2017 年 9 月)。
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 无 default 的穷举 switch
3+
oldApproach: 强制 default 分支
4+
modernApproach: 密封类穷举性
5+
summary: "编译器验证所有密封子类型均已覆盖——无需 default 分支。"
6+
explanation: "对密封类型进行 switch 时,编译器在编译时知道所有可能的子类型。如果所有情况均已覆盖,则不需要 default 分支。"
7+
whyModernWins:
8+
- icon:
9+
title: 编译时安全
10+
desc: "添加新子类型时,编译器会显示每个需要更新的地方。"
11+
- icon: 🚫
12+
title: 无死代码
13+
desc: "没有掩盖 bug 的不可达 default 分支。"
14+
- icon: 📐
15+
title: 代数类型
16+
desc: "密封类 + record + 穷举 switch = Java 中的正式 ADT。"
17+
support:
18+
description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 灵活的构造函数体
3+
oldApproach: 在 super() 之后验证
4+
modernApproach: 在 super() 之前编写代码
5+
summary: "在调用 super() 或 this() 之前验证和计算值。"
6+
explanation: "Java 25 解除了 super() 必须是第一条语句的限制。现在可以在超类构造函数运行之前验证参数、计算派生值并准备数据。"
7+
whyModernWins:
8+
- icon: 🛡️
9+
title: 快速失败
10+
desc: "在超类构造函数运行之前验证参数。"
11+
- icon: 🧮
12+
title: 预先计算
13+
desc: "在调用 super() 之前派生值并准备数据。"
14+
- icon: 🧹
15+
title: 无变通方案
16+
desc: "不再需要静态辅助方法或工厂模式来绕过该限制。"
17+
support:
18+
description: 在 JDK 25 LTS 中正式发布(JEP 513,2025 年 9 月)。
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 带 when 的守卫模式
3+
oldApproach: 嵌套 if
4+
modernApproach: when 子句
5+
summary: "使用 when 守卫向模式 case 添加条件。"
6+
explanation: "守卫模式让您使用 when 关键字通过额外的布尔条件来细化类型匹配。这替代了 switch 分支内的嵌套 if/else。"
7+
whyModernWins:
8+
- icon: 🎯
9+
title: 精确匹配
10+
desc: "在单个 case 标签中组合类型和条件。"
11+
- icon: 📐
12+
title: 扁平结构
13+
desc: "switch case 内无嵌套 if/else。"
14+
- icon: 📖
15+
title: 可读意图
16+
desc: "when 子句读起来像自然语言。"
17+
support:
18+
description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: Javadoc 注释中的 Markdown
3+
oldApproach: 基于 HTML 的 Javadoc
4+
modernApproach: Markdown Javadoc
5+
summary: "用 Markdown 而非 HTML 编写 Javadoc 注释,提高可读性。"
6+
explanation: "Java 23 引入了 /// Markdown 风格的 Javadoc 注释,作为 /** HTML Javadoc 的替代方案。它们在生成的 HTML 文档中正确渲染。"
7+
whyModernWins:
8+
- icon: 📖
9+
title: 自然语法
10+
desc: "使用反引号表示行内代码,使用 ``` 表示代码块,而非 HTML 标签。"
11+
- icon: ✍️
12+
title: 更易编写
13+
desc: '无需 {@code}、<pre>、<p> 标签——直接编写 Markdown。'
14+
- icon: 👁
15+
title: 编辑器中更美观
16+
desc: "Markdown 在现代 IDE 和文本编辑器中渲染效果极佳。"
17+
support:
18+
description: 自 JDK 23 起可用(2024 年 9 月)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: 模块导入声明
3+
oldApproach: 大量 import 语句
4+
modernApproach: import module
5+
summary: "用单个声明导入模块导出的所有包。"
6+
explanation: "模块导入声明让您用单个 import module 语句导入模块导出的所有内容,替代大量单独的包导入。"
7+
whyModernWins:
8+
- icon: 🧹
9+
title: 一行搞定
10+
desc: "用单个模块导入替代大量 import 语句。"
11+
- icon: 📦
12+
title: 模块感知
13+
desc: "利用模块系统导入一致的包集合。"
14+
- icon: 🚀
15+
title: 快速启动
16+
desc: "非常适合脚本和原型,无需繁琐的 import 列表。"
17+
support:
18+
description: 在 JDK 25 LTS 中正式发布(JEP 511,2025 年 9 月)。
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
title: instanceof 的模式匹配
3+
oldApproach: instanceof + 强制类型转换
4+
modernApproach: 模式变量
5+
summary: "通过模式匹配在一步中组合类型检查和转换。"
6+
explanation: "instanceof 的模式匹配消除了 instanceof 检查后冗余的类型转换。绑定变量自动具有正确的类型和作用域。"
7+
whyModernWins:
8+
- icon: 🔄
9+
title: 无冗余转换
10+
desc: "类型检查和变量绑定在单个表达式中完成。"
11+
- icon: 📏
12+
title: 更少代码行
13+
desc: "一行代替两行——转换行完全消失。"
14+
- icon: 🛡️
15+
title: 作用域安全
16+
desc: "模式变量仅在保证类型正确的作用域内有效。"
17+
support:
18+
description: 自 JDK 16 起广泛可用(2021 年 3 月)

0 commit comments

Comments
 (0)