diff --git a/html-generators/locales.properties b/html-generators/locales.properties index 56a72d3..d3e5ff9 100644 --- a/html-generators/locales.properties +++ b/html-generators/locales.properties @@ -3,6 +3,7 @@ en=English de=Deutsch es=Español pt-BR=Português (Brasil) +zh-CN=中文 (简体) ar=العربية fr=Français ja=日本語 diff --git a/translations/content/zh-CN/collections/collectors-teeing.yaml b/translations/content/zh-CN/collections/collectors-teeing.yaml new file mode 100644 index 0000000..9323193 --- /dev/null +++ b/translations/content/zh-CN/collections/collectors-teeing.yaml @@ -0,0 +1,18 @@ +--- +title: Collectors.teeing() +oldApproach: 两次遍历 +modernApproach: teeing() +summary: "在单次流遍历中计算两个聚合结果。" +explanation: "Collectors.teeing() 将每个元素发送到两个下游收集器,然后将结果合并。不再需要对流进行两次遍历或将中间结果存储在可变变量中。" +whyModernWins: +- icon: ⚡ + title: 单次遍历 + desc: "只处理流一次,而非两次。" +- icon: 🧹 + title: 无可变状态 + desc: "无需用于收集中间结果的临时变量。" +- icon: 🧩 + title: 可组合 + desc: "可与其他收集器组合作为下游收集器。" +support: + description: 自 JDK 12 起广泛可用(2019 年 3 月) diff --git a/translations/content/zh-CN/collections/copying-collections-immutably.yaml b/translations/content/zh-CN/collections/copying-collections-immutably.yaml new file mode 100644 index 0000000..f4f81a6 --- /dev/null +++ b/translations/content/zh-CN/collections/copying-collections-immutably.yaml @@ -0,0 +1,18 @@ +--- +title: 不可变地复制集合 +oldApproach: 手动复制 + 包装 +modernApproach: List.copyOf() +summary: "一次调用创建任何集合的不可变副本。" +explanation: "List.copyOf()、Set.copyOf() 和 Map.copyOf() 创建不可变快照。如果源集合已经是不可变的,则跳过复制——这一实现细节对调用者透明。" +whyModernWins: +- icon: ⚡ + title: 智能复制 + desc: "如果源已经是不可变的,则跳过复制。" +- icon: 🔒 + title: 真正不可变 + desc: "结果集合结构上不可修改。" +- icon: 📏 + title: 简洁 + desc: "一行代码替代多行手动复制和包装。" +support: + description: 自 JDK 10 起广泛可用(2018 年 3 月) diff --git a/translations/content/zh-CN/collections/immutable-list-creation.yaml b/translations/content/zh-CN/collections/immutable-list-creation.yaml new file mode 100644 index 0000000..6b3138c --- /dev/null +++ b/translations/content/zh-CN/collections/immutable-list-creation.yaml @@ -0,0 +1,18 @@ +--- +title: 创建不可变列表 +oldApproach: 冗长的包装方式 +modernApproach: List.of() +summary: "用一个简洁的表达式创建不可变列表。" +explanation: "List.of() 创建真正不可变的列表——无需包装,无需防御性复制。它拒绝 null 元素,在结构上不可变。旧方式需要三层嵌套调用。" +whyModernWins: +- icon: 📏 + title: 一次调用 + desc: "用单个工厂方法替代三层嵌套调用。" +- icon: 🔒 + title: 真正不可变 + desc: "不只是包装器——列表本身是不可变的。" +- icon: 🛡️ + title: null 安全 + desc: "在创建时拒绝 null 元素,快速失败。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/collections/immutable-map-creation.yaml b/translations/content/zh-CN/collections/immutable-map-creation.yaml new file mode 100644 index 0000000..0cadeca --- /dev/null +++ b/translations/content/zh-CN/collections/immutable-map-creation.yaml @@ -0,0 +1,18 @@ +--- +title: 创建不可变 Map +oldApproach: Map 构建器模式 +modernApproach: Map.of() +summary: "无需构建器即可内联创建不可变 Map。" +explanation: "Map.of() 内联接受键值对并返回不可变 Map。Map.ofEntries() 处理超过 10 个条目的情况。旧方式需要可变的临时 Map 和 Collections.unmodifiableMap()。" +whyModernWins: +- icon: 📏 + title: 内联创建 + desc: "无需临时可变 Map。" +- icon: 🔒 + title: 真正不可变 + desc: "Map 本身不可修改,不只是视图。" +- icon: 🛡️ + title: null 安全 + desc: "键和值均拒绝 null,快速失败。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/collections/immutable-set-creation.yaml b/translations/content/zh-CN/collections/immutable-set-creation.yaml new file mode 100644 index 0000000..4274506 --- /dev/null +++ b/translations/content/zh-CN/collections/immutable-set-creation.yaml @@ -0,0 +1,18 @@ +--- +title: 创建不可变 Set +oldApproach: 冗长的包装方式 +modernApproach: Set.of() +summary: "用单个工厂调用创建不可变 Set。" +explanation: "Set.of() 创建真正不可变的 Set,拒绝 null 和重复元素。迭代顺序不保证——如果需要顺序,使用 LinkedHashSet 或 List.of()。" +whyModernWins: +- icon: 📏 + title: 简洁 + desc: "一行代码替代三层嵌套调用。" +- icon: 🔒 + title: 真正不可变 + desc: "Set 本身不可修改。" +- icon: 🛡️ + title: null 安全 + desc: "在创建时拒绝 null 元素。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/collections/map-entry-factory.yaml b/translations/content/zh-CN/collections/map-entry-factory.yaml new file mode 100644 index 0000000..4a6642a --- /dev/null +++ b/translations/content/zh-CN/collections/map-entry-factory.yaml @@ -0,0 +1,18 @@ +--- +title: Map.entry() 工厂方法 +oldApproach: SimpleEntry +modernApproach: Map.entry() +summary: "使用简洁的工厂方法创建 Map 条目。" +explanation: "Map.entry() 替代冗长的 AbstractMap.SimpleEntry 构造函数。结果条目是不可变的——键和值均不能更改。" +whyModernWins: +- icon: 📏 + title: 简洁 + desc: "一行代码,意图更清晰。" +- icon: 🔒 + title: 不可变 + desc: "条目创建后无法修改。" +- icon: 🎯 + title: 语义清晰 + desc: "Map.entry() 准确表达您的意图。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/collections/reverse-list-iteration.yaml b/translations/content/zh-CN/collections/reverse-list-iteration.yaml new file mode 100644 index 0000000..4eaf8d7 --- /dev/null +++ b/translations/content/zh-CN/collections/reverse-list-iteration.yaml @@ -0,0 +1,18 @@ +--- +title: 反向列表迭代 +oldApproach: 手动 ListIterator +modernApproach: reversed() +summary: "使用简洁的 for-each 循环以相反顺序迭代列表。" +explanation: "SequencedCollection 中的 reversed() 方法返回一个反向排序的视图,不进行复制。这与 for-each 循环完美配合,无需 ListIterator 样板。" +whyModernWins: +- icon: 📖 + title: 自然语法 + desc: "增强 for 循环,而非冗长的 ListIterator。" +- icon: 🔒 + title: 无复制 + desc: "reversed() 是视图,不复制列表。" +- icon: 📏 + title: 更少代码 + desc: "六行 ListIterator 样板变为一行。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/collections/sequenced-collections.yaml b/translations/content/zh-CN/collections/sequenced-collections.yaml new file mode 100644 index 0000000..477d3e7 --- /dev/null +++ b/translations/content/zh-CN/collections/sequenced-collections.yaml @@ -0,0 +1,18 @@ +--- +title: 有序集合 +oldApproach: 索引运算 +modernApproach: getFirst/getLast +summary: "使用简洁的 API 方法访问第一个/最后一个元素和反向视图。" +explanation: "SequencedCollection 添加了 getFirst()、getLast()、reversed()、addFirst()、addLast() 和 removeFirst()/removeLast()。这些方法统一了 List、Deque 和 LinkedHashSet 的 API。" +whyModernWins: +- icon: 📖 + title: 自我描述 + desc: "getLast() 比 get(size()-1) 更清晰。" +- icon: 🔗 + title: 统一 API + desc: "List、Deque 和 LinkedHashSet 共享相同的有序操作。" +- icon: 🔒 + title: 反向视图 + desc: "reversed() 返回视图,不复制集合。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/collections/stream-toarray-typed.yaml b/translations/content/zh-CN/collections/stream-toarray-typed.yaml new file mode 100644 index 0000000..66471fe --- /dev/null +++ b/translations/content/zh-CN/collections/stream-toarray-typed.yaml @@ -0,0 +1,18 @@ +--- +title: 类型化流 toArray +oldApproach: 手动数组复制 +modernApproach: toArray(generator) +summary: "使用方法引用将流转换为类型化数组。" +explanation: "toArray(IntFunction) 方法从流创建正确类型化的数组。传递 String[]::new 获取 String[],而非 Object[]。" +whyModernWins: +- icon: 🎯 + title: 类型安全 + desc: "没有 Object[] 转换——数组类型是正确的。" +- icon: 📏 + title: 简洁 + desc: "方法引用语法简洁而具有表达力。" +- icon: 🚫 + title: 无 System.arraycopy + desc: "不需要中间 Object[] 和数组复制。" +support: + description: 自 JDK 8 起广泛可用(2014 年 3 月) diff --git a/translations/content/zh-CN/collections/unmodifiable-collectors.yaml b/translations/content/zh-CN/collections/unmodifiable-collectors.yaml new file mode 100644 index 0000000..5ef851d --- /dev/null +++ b/translations/content/zh-CN/collections/unmodifiable-collectors.yaml @@ -0,0 +1,18 @@ +--- +title: 不可修改收集器 +oldApproach: collectingAndThen +modernApproach: stream.toList() +summary: "使用 stream.toList() 直接收集到不可修改列表。" +explanation: "Java 10 添加了 toUnmodifiableList()、toUnmodifiableSet() 和 toUnmodifiableMap()。Java 16 的 stream.toList() 更进一步,完全不需要 collect() 或 Collectors 导入。" +whyModernWins: +- icon: 📏 + title: 最简洁 + desc: "stream.toList() 完全不需要 collect() 或 Collectors 导入。" +- icon: 🔒 + title: 真正不可变 + desc: "结果列表在结构上不可修改。" +- icon: 🧹 + title: 更少导入 + desc: "无需导入 java.util.stream.Collectors。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/concurrency/completablefuture-chaining.yaml b/translations/content/zh-CN/concurrency/completablefuture-chaining.yaml new file mode 100644 index 0000000..0f6fc0c --- /dev/null +++ b/translations/content/zh-CN/concurrency/completablefuture-chaining.yaml @@ -0,0 +1,18 @@ +--- +title: CompletableFuture 链式调用 +oldApproach: 阻塞式 Future.get() +modernApproach: CompletableFuture +summary: "使用 CompletableFuture 链式异步操作,无需阻塞。" +explanation: "CompletableFuture 支持非阻塞异步管道。链式操作使用 thenApply、thenCompose 和 thenCombine,仅在最终结果需要时阻塞。" +whyModernWins: +- icon: 🔗 + title: 可链式调用 + desc: "将异步步骤组合成可读的管道。" +- icon: ⚡ + title: 非阻塞 + desc: "线程不会等待中间结果——只在需要时阻塞。" +- icon: 🔀 + title: 可组合 + desc: "使用 thenCombine、allOf、anyOf 组合多个 Future。" +support: + description: 自 JDK 8 起广泛可用(2014 年 3 月) diff --git a/translations/content/zh-CN/concurrency/concurrent-http-virtual.yaml b/translations/content/zh-CN/concurrency/concurrent-http-virtual.yaml new file mode 100644 index 0000000..6eddff5 --- /dev/null +++ b/translations/content/zh-CN/concurrency/concurrent-http-virtual.yaml @@ -0,0 +1,18 @@ +--- +title: 使用虚拟线程进行并发 HTTP 请求 +oldApproach: 线程池 + URLConnection +modernApproach: 虚拟线程 + HttpClient +summary: "使用虚拟线程和 HttpClient 并发获取多个 URL。" +explanation: "虚拟线程使每个 HTTP 请求使用一个线程变得切实可行。每个虚拟线程在等待 I/O 时会挂载,不会阻塞平台线程。" +whyModernWins: +- icon: ♾️ + title: 每个请求一个线程 + desc: "无需调整池大小——每个 URL 一个虚拟线程。" +- icon: 🔒 + title: 简单的错误处理 + desc: "每个任务在自己的线程中处理错误。" +- icon: 📏 + title: 简洁代码 + desc: "现代 HttpClient 与虚拟线程的语义清晰。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/concurrency/executor-try-with-resources.yaml b/translations/content/zh-CN/concurrency/executor-try-with-resources.yaml new file mode 100644 index 0000000..d1a8e47 --- /dev/null +++ b/translations/content/zh-CN/concurrency/executor-try-with-resources.yaml @@ -0,0 +1,18 @@ +--- +title: ExecutorService 自动关闭 +oldApproach: 手动关闭 +modernApproach: try-with-resources +summary: "使用 try-with-resources 实现执行器的自动关闭。" +explanation: "自 Java 19 起,ExecutorService 实现了 AutoCloseable。close() 方法会等待所有任务完成,然后关闭执行器——无需手动 shutdown() 和 awaitTermination()。" +whyModernWins: +- icon: 🧹 + title: 自动清理 + desc: "当代码块退出时自动关闭。" +- icon: 🛡️ + title: 不会泄漏线程 + desc: "即使抛出异常,执行器也会正确关闭。" +- icon: 📏 + title: 更少样板代码 + desc: "无需手动 try/finally 来调用 shutdown()。" +support: + description: 自 JDK 19 起广泛可用(2022 年 9 月) diff --git a/translations/content/zh-CN/concurrency/lock-free-lazy-init.yaml b/translations/content/zh-CN/concurrency/lock-free-lazy-init.yaml new file mode 100644 index 0000000..def34e7 --- /dev/null +++ b/translations/content/zh-CN/concurrency/lock-free-lazy-init.yaml @@ -0,0 +1,18 @@ +--- +title: 无锁延迟初始化 +oldApproach: synchronized + volatile +modernApproach: StableValue +summary: "用 StableValue 替代双重检查锁定,实现延迟单例。" +explanation: "StableValue 以正确的内存语义封装延迟初始化模式。它消除了对 volatile、synchronized 和双重 null 检查的需要。" +whyModernWins: +- icon: 🧹 + title: 无样板代码 + desc: "无 volatile、synchronized 或双重 null 检查。" +- icon: 🔒 + title: 正确的内存语义 + desc: "JVM 保证正确的可见性,无需手动内存屏障。" +- icon: 📖 + title: 意图清晰 + desc: "StableValue 的名称准确描述了其语义。" +support: + description: JDK 25 预览版(JEP 502,StableValue)。需要 --enable-preview。 diff --git a/translations/content/zh-CN/concurrency/process-api.yaml b/translations/content/zh-CN/concurrency/process-api.yaml new file mode 100644 index 0000000..d5e6df7 --- /dev/null +++ b/translations/content/zh-CN/concurrency/process-api.yaml @@ -0,0 +1,18 @@ +--- +title: 现代 Process API +oldApproach: Runtime.exec() +modernApproach: ProcessHandle +summary: "使用 ProcessHandle 检查和管理操作系统进程。" +explanation: "ProcessHandle 提供 PID、进程信息(命令、参数、启动时间)以及监控子进程的能力。ProcessBuilder 提供了对 stdin/stdout/stderr 的精细控制。" +whyModernWins: +- icon: 🔍 + title: 完整信息 + desc: "访问 PID、命令、参数、启动时间、CPU 使用率。" +- icon: 👶 + title: 子进程管理 + desc: "列出和监控子进程。" +- icon: 🔔 + title: 终止回调 + desc: "进程终止时获得通知。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/concurrency/scoped-values.yaml b/translations/content/zh-CN/concurrency/scoped-values.yaml new file mode 100644 index 0000000..fbc5ea9 --- /dev/null +++ b/translations/content/zh-CN/concurrency/scoped-values.yaml @@ -0,0 +1,18 @@ +--- +title: 作用域值 +oldApproach: ThreadLocal +modernApproach: ScopedValue +summary: "安全地跨调用栈共享数据,无 ThreadLocal 的陷阱。" +explanation: "ScopedValue 提供不可变的、可继承的、作用域受限的上下文。与 ThreadLocal 不同,它适用于虚拟线程,不会泄漏状态,在结构化并发中效果极佳。" +whyModernWins: +- icon: 🔒 + title: 不可变 + desc: "被调用方可以读取但永远不能修改作用域值。" +- icon: 🧵 + title: 虚拟线程友好 + desc: "与虚拟线程和结构化并发配合良好。" +- icon: 🧹 + title: 无泄漏 + desc: "作用域退出时自动清理——无需 remove()。" +support: + description: 在 JDK 25 LTS 中正式发布(JEP 506,2025 年 9 月)。 diff --git a/translations/content/zh-CN/concurrency/stable-values.yaml b/translations/content/zh-CN/concurrency/stable-values.yaml new file mode 100644 index 0000000..d087828 --- /dev/null +++ b/translations/content/zh-CN/concurrency/stable-values.yaml @@ -0,0 +1,18 @@ +--- +title: 稳定值 +oldApproach: 双重检查锁定 +modernApproach: StableValue +summary: "无需 volatile 或 synchronized 的线程安全延迟初始化。" +explanation: "StableValue 提供内置线程安全的延迟初始化不可变值。JVM 知道该值只写入一次,可以进行更激进的优化,包括常量折叠。" +whyModernWins: +- icon: 🧹 + title: 零样板代码 + desc: "无 volatile、synchronized 或 null 检查。" +- icon: ⚡ + title: JVM 优化 + desc: "JVM 可以将稳定值常量折叠,就像 final 字段一样。" +- icon: 🔒 + title: 线程安全 + desc: "保证只初始化一次,不存在竞态条件。" +support: + description: JDK 25 预览版(JEP 502)。需要 --enable-preview。 diff --git a/translations/content/zh-CN/concurrency/structured-concurrency.yaml b/translations/content/zh-CN/concurrency/structured-concurrency.yaml new file mode 100644 index 0000000..11d3d44 --- /dev/null +++ b/translations/content/zh-CN/concurrency/structured-concurrency.yaml @@ -0,0 +1,18 @@ +--- +title: 结构化并发 +oldApproach: 手动线程生命周期管理 +modernApproach: StructuredTaskScope +summary: "将并发任务的生命周期作为单个工作单元管理。" +explanation: "结构化并发将一组并发任务视为一个操作。如果任何任务失败,其他任务会被取消。所有分支任务在作用域关闭前完成。" +whyModernWins: +- icon: 🛡️ + title: 无线程泄漏 + desc: "所有分支任务在作用域关闭前完成。" +- icon: 🔗 + title: 错误传播 + desc: "任何任务失败时取消其他任务。" +- icon: 📖 + title: 可读结构 + desc: "并发边界在代码结构中清晰可见。" +support: + description: JDK 25 预览版(第五次预览,JEP 505)。需要 --enable-preview。 diff --git a/translations/content/zh-CN/concurrency/thread-sleep-duration.yaml b/translations/content/zh-CN/concurrency/thread-sleep-duration.yaml new file mode 100644 index 0000000..d91cf49 --- /dev/null +++ b/translations/content/zh-CN/concurrency/thread-sleep-duration.yaml @@ -0,0 +1,18 @@ +--- +title: 使用 Duration 的 Thread.sleep +oldApproach: 毫秒 +modernApproach: Duration +summary: "使用 Duration 表达自文档化的时间值。" +explanation: "Thread.sleep(Duration) 使时间单位明确。不再需要猜测数字是毫秒、秒还是纳秒——Duration.ofSeconds(5) 一目了然。" +whyModernWins: +- icon: 📖 + title: 自我描述 + desc: "Duration.ofSeconds(5) 无歧义。" +- icon: 🛡️ + title: 无单位混淆 + desc: "不可能意外地将秒传递给期望毫秒的方法。" +- icon: 🔧 + title: 可组合 + desc: "Duration 与其他 java.time API 无缝配合。" +support: + description: 自 JDK 19 起广泛可用(2022 年 9 月) diff --git a/translations/content/zh-CN/concurrency/virtual-threads.yaml b/translations/content/zh-CN/concurrency/virtual-threads.yaml new file mode 100644 index 0000000..6a8b2fb --- /dev/null +++ b/translations/content/zh-CN/concurrency/virtual-threads.yaml @@ -0,0 +1,18 @@ +--- +title: 虚拟线程 +oldApproach: 平台线程 +modernApproach: 虚拟线程 +summary: "创建数百万个轻量级虚拟线程,而非沉重的操作系统线程。" +explanation: "虚拟线程是由 JVM 而非操作系统管理的轻量级线程。它们挂起时不会阻塞平台线程,使每个请求一个线程的风格变得可行。" +whyModernWins: +- icon: ⚡ + title: 轻量级 + desc: "虚拟线程使用 KB 内存,平台线程使用 MB。" +- icon: ♾️ + title: 可扩展 + desc: "每个请求运行一个线程,无需异步代码。" +- icon: 🔧 + title: 无需重构 + desc: "与现有阻塞 API(JDBC、文件 I/O)配合使用。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/datetime/date-formatting.yaml b/translations/content/zh-CN/datetime/date-formatting.yaml new file mode 100644 index 0000000..96840b5 --- /dev/null +++ b/translations/content/zh-CN/datetime/date-formatting.yaml @@ -0,0 +1,18 @@ +--- +title: 日期格式化 +oldApproach: SimpleDateFormat +modernApproach: DateTimeFormatter +summary: "使用线程安全、不可变的 DateTimeFormatter 格式化日期。" +explanation: "DateTimeFormatter 是不可变且线程安全的,与 SimpleDateFormat 不同。它可以作为静态常量安全共享,支持 java.time 类型并提供更丰富的格式化选项。" +whyModernWins: +- icon: 🛡️ + title: 线程安全 + desc: "跨线程共享格式化器,无需同步。" +- icon: 🔒 + title: 不可变 + desc: "无并发 bug——格式化器不能被修改。" +- icon: 📐 + title: 更丰富的 API + desc: "支持所有 java.time 类型,具有更好的本地化支持。" +support: + description: 自 JDK 8 起广泛可用(2014 年 3 月) diff --git a/translations/content/zh-CN/datetime/duration-and-period.yaml b/translations/content/zh-CN/datetime/duration-and-period.yaml new file mode 100644 index 0000000..faf0573 --- /dev/null +++ b/translations/content/zh-CN/datetime/duration-and-period.yaml @@ -0,0 +1,18 @@ +--- +title: Duration 和 Period +oldApproach: 毫秒数学 +modernApproach: Duration / Period +summary: "使用类型安全的 Duration 和 Period 计算时间差。" +explanation: "Duration 用于基于时间的量(小时、分钟、秒)。Period 用于日期量(年、月、日)。两者都是不可变的,并且支持算术运算。" +whyModernWins: +- icon: 🎯 + title: 类型安全 + desc: "Duration 用于时间,Period 用于日期——不会混淆。" +- icon: 📖 + title: 自我描述 + desc: "Duration.ofDays(7) 比 7 * 24 * 60 * 60 * 1000L 更清晰。" +- icon: 🔒 + title: 不可变 + desc: "时间量是值类型——不能意外修改。" +support: + description: 自 JDK 8 起广泛可用(2014 年 3 月) diff --git a/translations/content/zh-CN/datetime/hex-format.yaml b/translations/content/zh-CN/datetime/hex-format.yaml new file mode 100644 index 0000000..18f297c --- /dev/null +++ b/translations/content/zh-CN/datetime/hex-format.yaml @@ -0,0 +1,18 @@ +--- +title: HexFormat +oldApproach: 手动十六进制转换 +modernApproach: HexFormat +summary: "使用 HexFormat 在十六进制字符串和字节数组之间转换。" +explanation: "HexFormat 提供字节、整数和长整型的双向十六进制编码/解码。它支持大写/小写、分隔符和前缀/后缀配置。" +whyModernWins: +- icon: 📐 + title: 双向 + desc: "用一个 API 实现字节→十六进制和十六进制→字节转换。" +- icon: 🔧 + title: 可配置 + desc: "大写、分隔符、前缀/后缀均可自定义。" +- icon: 📏 + title: 简洁 + desc: "替代脆弱的手动 String.format 十六进制代码。" +support: + description: 自 JDK 17 LTS 起广泛可用(2021 年 9 月) diff --git a/translations/content/zh-CN/datetime/instant-precision.yaml b/translations/content/zh-CN/datetime/instant-precision.yaml new file mode 100644 index 0000000..77674c1 --- /dev/null +++ b/translations/content/zh-CN/datetime/instant-precision.yaml @@ -0,0 +1,18 @@ +--- +title: 纳秒精度的 Instant +oldApproach: 毫秒 +modernApproach: 纳秒 +summary: "获取微秒或纳秒精度的时间戳。" +explanation: "Java 9 改进了时钟分辨率,使 Instant.now() 在支持的平台上可以捕获微秒甚至纳秒精度。对于需要高精度计时的基准测试和诊断非常有用。" +whyModernWins: +- icon: 🎯 + title: 更高精度 + desc: "微秒/纳秒 vs 毫秒时间戳。" +- icon: 🔧 + title: 诊断友好 + desc: "更精确的时间测量,用于性能基准测试。" +- icon: 📐 + title: 平台利用 + desc: "在支持高分辨率的平台上自动使用。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/datetime/java-time-basics.yaml b/translations/content/zh-CN/datetime/java-time-basics.yaml new file mode 100644 index 0000000..b74b12d --- /dev/null +++ b/translations/content/zh-CN/datetime/java-time-basics.yaml @@ -0,0 +1,18 @@ +--- +title: java.time API 基础 +oldApproach: Date + Calendar +modernApproach: java.time.* +summary: "使用不可变、清晰的日期/时间类型替代 Date 和 Calendar。" +explanation: "java.time 提供 LocalDate、LocalTime、LocalDateTime、Instant、ZonedDateTime 等。它们是不可变的、线程安全的,并且设计清晰——与可变且混乱的 Date/Calendar 不同。" +whyModernWins: +- icon: 🔒 + title: 不可变 + desc: "日期/时间值不能被意外修改。" +- icon: 📖 + title: 语义清晰 + desc: "LocalDate vs ZonedDateTime vs Instant——每种类型都有明确用途。" +- icon: 🌐 + title: 时区安全 + desc: "时区处理是显式的,而非隐藏的。" +support: + description: 自 JDK 8 起广泛可用(2014 年 3 月) diff --git a/translations/content/zh-CN/datetime/math-clamp.yaml b/translations/content/zh-CN/datetime/math-clamp.yaml new file mode 100644 index 0000000..9e60d4e --- /dev/null +++ b/translations/content/zh-CN/datetime/math-clamp.yaml @@ -0,0 +1,18 @@ +--- +title: Math.clamp() +oldApproach: 嵌套 min/max +modernApproach: Math.clamp() +summary: "用单个清晰的调用将值限制在边界之间。" +explanation: "Math.clamp(value, min, max) 将值约束在范围 [min, max] 内。如果 min > max,则抛出 IllegalArgumentException。它适用于 int、long、float 和 double。" +whyModernWins: +- icon: 📖 + title: 自我描述 + desc: "clamp(value, min, max) 无歧义。" +- icon: 📏 + title: 简洁 + desc: "替代嵌套的 Math.min(max, Math.max(min, value))。" +- icon: 🔒 + title: 验证 + desc: "当 min > max 时抛出,捕获错误范围。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/enterprise/ejb-timer-vs-jakarta-scheduler.yaml b/translations/content/zh-CN/enterprise/ejb-timer-vs-jakarta-scheduler.yaml new file mode 100644 index 0000000..fe127ce --- /dev/null +++ b/translations/content/zh-CN/enterprise/ejb-timer-vs-jakarta-scheduler.yaml @@ -0,0 +1,18 @@ +--- +title: EJB Timer 与 Jakarta 调度器 +oldApproach: EJB TimerService +modernApproach: ManagedScheduledExecutorService +summary: "用 Jakarta Concurrency 的 ManagedScheduledExecutorService 替代重量级 EJB 定时器。" +explanation: "EJB 定时器需要带有 @Timeout 回调和 ScheduleExpression 配置的 @Stateless 或 @Singleton bean。ManagedScheduledExecutorService 使用标准 ScheduledExecutorService API,语法更简洁。" +whyModernWins: +- icon: 🪶 + title: 减少样板代码 + desc: "无需 @Timeout 回调或 ScheduleExpression——使用标准 ScheduledExecutorService API。" +- icon: 🔧 + title: 标准 API + desc: "基于 java.util.concurrent 接口,熟悉且可测试。" +- icon: 🧪 + title: 更易测试 + desc: "可以在单元测试中注入模拟调度器,EJB 定时器则不行。" +support: + description: 自 Jakarta EE 10 / Concurrency 3.0 起可用 diff --git a/translations/content/zh-CN/enterprise/ejb-vs-cdi.yaml b/translations/content/zh-CN/enterprise/ejb-vs-cdi.yaml new file mode 100644 index 0000000..05f14a4 --- /dev/null +++ b/translations/content/zh-CN/enterprise/ejb-vs-cdi.yaml @@ -0,0 +1,18 @@ +--- +title: EJB 与 CDI +oldApproach: EJB +modernApproach: CDI Bean +summary: "用轻量级 CDI bean 替代重量级 EJB,实现依赖注入和业务逻辑。" +explanation: "CDI(上下文和依赖注入)提供与 EJB 相同的依赖注入和生命周期管理,无需 EJB 特定接口或描述符。CDI bean 是普通 Java 类,容器负责其余工作。" +whyModernWins: +- icon: 🪶 + title: 轻量级 + desc: "CDI bean 是普通 Java 类,无需 EJB 特定接口或描述符。" +- icon: 🧪 + title: 更易测试 + desc: "普通 Java 对象,无需 EJB 容器即可进行单元测试。" +- icon: 🔧 + title: 现代标准 + desc: "CDI 是 Jakarta EE 的推荐注入机制,持续演进。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/jdbc-resultset-vs-jpa-criteria.yaml b/translations/content/zh-CN/enterprise/jdbc-resultset-vs-jpa-criteria.yaml new file mode 100644 index 0000000..4f8d6be --- /dev/null +++ b/translations/content/zh-CN/enterprise/jdbc-resultset-vs-jpa-criteria.yaml @@ -0,0 +1,18 @@ +--- +title: JDBC ResultSet 映射与 JPA Criteria API +oldApproach: JDBC ResultSet +modernApproach: JPA Criteria API +summary: "用 JPA 类型安全的 Criteria API 替代手动 JDBC ResultSet 映射。" +explanation: "原始 JDBC 需要构建 SQL 字符串、按索引设置参数、手动映射每列。JPA Criteria API 在编译时捕获字段名称和类型不匹配。" +whyModernWins: +- icon: 🔒 + title: 类型安全查询 + desc: "Criteria 构建器在编译时捕获字段名称和类型不匹配。" +- icon: 🗺️ + title: 自动映射 + desc: "结果直接映射到实体对象——无需手动 ResultSet 处理。" +- icon: 🔧 + title: 可重构 + desc: "重命名字段会在 Criteria 查询中产生编译错误。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/jdbc-vs-jooq.yaml b/translations/content/zh-CN/enterprise/jdbc-vs-jooq.yaml new file mode 100644 index 0000000..3a6f4cc --- /dev/null +++ b/translations/content/zh-CN/enterprise/jdbc-vs-jooq.yaml @@ -0,0 +1,18 @@ +--- +title: JDBC 与 jOOQ +oldApproach: 原始 JDBC +modernApproach: jOOQ SQL DSL +summary: "用 jOOQ 类型安全的流畅 SQL DSL 替代原始 JDBC 字符串 SQL。" +explanation: "jOOQ(Java Object Oriented Querying)从数据库生成 Java 代码,提供类型安全的 SQL 构建。列名是生成的 Java 常量,因此拼写错误在编译时而非运行时捕获。" +whyModernWins: +- icon: 🔒 + title: 类型安全的列 + desc: "列名是生成的 Java 常量——拼写错误和类型不匹配成为编译错误。" +- icon: 📖 + title: SQL 流畅性 + desc: "DSL 读起来像 SQL,但具有 Java 的类型安全性。" +- icon: 🔧 + title: 数据库模式感知 + desc: "从实际数据库模式生成,始终与真实列对齐。" +support: + description: jOOQ 开源版支持所有主要开源数据库;商业版支持专有数据库 diff --git a/translations/content/zh-CN/enterprise/jdbc-vs-jpa.yaml b/translations/content/zh-CN/enterprise/jdbc-vs-jpa.yaml new file mode 100644 index 0000000..2b57c3f --- /dev/null +++ b/translations/content/zh-CN/enterprise/jdbc-vs-jpa.yaml @@ -0,0 +1,18 @@ +--- +title: JDBC 与 JPA +oldApproach: JDBC +modernApproach: JPA EntityManager +summary: "用 JPA 的对象关系映射和 EntityManager API 替代冗长的 JDBC 样板代码。" +explanation: "JPA(Jakarta Persistence API)将 Java 对象映射到数据库行,消除了手动 SQL、ResultSet 映射和参数设置。EntityManager 提供高级查询和关系管理。" +whyModernWins: +- icon: 🗺️ + title: 对象映射 + desc: "实体是带注解的普通类——无需手动 ResultSet 到对象的转换。" +- icon: 🔧 + title: 关系处理 + desc: "一对多、多对多等关系由 JPA 自动处理。" +- icon: 📏 + title: 更少代码 + desc: "消除大量 JDBC 样板——连接、语句、关闭。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/jndi-lookup-vs-cdi-injection.yaml b/translations/content/zh-CN/enterprise/jndi-lookup-vs-cdi-injection.yaml new file mode 100644 index 0000000..f4dde78 --- /dev/null +++ b/translations/content/zh-CN/enterprise/jndi-lookup-vs-cdi-injection.yaml @@ -0,0 +1,18 @@ +--- +title: JNDI 查找与 CDI 注入 +oldApproach: JNDI 查找 +modernApproach: CDI @Inject +summary: "用类型安全的 CDI 注入替代脆弱的 JNDI 字符串查找,用于容器管理资源。" +explanation: "传统 JNDI 模式强制使用基于字符串的资源名称,在部署时绑定,导致脆弱的运行时错误。CDI @Inject 在部署时进行类型安全的连接。" +whyModernWins: +- icon: 🔒 + title: 类型安全连接 + desc: "注入错误在部署时捕获,而非通过字符串查找在运行时捕获。" +- icon: 🧪 + title: 可测试 + desc: "CDI bean 可以在单元测试中注入模拟——JNDI 查找则不行。" +- icon: 📖 + title: 显式依赖 + desc: "@Inject 字段使依赖关系清晰可见。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/jpa-vs-jakarta-data.yaml b/translations/content/zh-CN/enterprise/jpa-vs-jakarta-data.yaml new file mode 100644 index 0000000..f0d71cb --- /dev/null +++ b/translations/content/zh-CN/enterprise/jpa-vs-jakarta-data.yaml @@ -0,0 +1,18 @@ +--- +title: JPA 与 Jakarta Data +oldApproach: JPA EntityManager +modernApproach: Jakarta Data Repository +summary: "声明 Repository 接口,让 Jakarta Data 生成 DAO 实现。" +explanation: "Jakarta Data(Jakarta EE 11)将数据访问变为纯接口声明。容器生成完整的 DAO 实现——无需 EntityManager 样板、查询构建器或手动事务。" +whyModernWins: +- icon: 🪄 + title: 零样板代码 + desc: "声明接口;容器生成完整的 DAO 实现。" +- icon: 📖 + title: 表达性查询 + desc: "方法名成为查询:findByLastNameOrderByFirstName。" +- icon: 🔒 + title: 类型安全 + desc: "方法签名在编译时验证参数和返回类型。" +support: + description: 自 Jakarta EE 11 / Java 21 起可用(2024 年) diff --git a/translations/content/zh-CN/enterprise/jsf-managed-bean-vs-cdi-named.yaml b/translations/content/zh-CN/enterprise/jsf-managed-bean-vs-cdi-named.yaml new file mode 100644 index 0000000..f04610c --- /dev/null +++ b/translations/content/zh-CN/enterprise/jsf-managed-bean-vs-cdi-named.yaml @@ -0,0 +1,18 @@ +--- +title: JSF Managed Bean 与 CDI Named Bean +oldApproach: '@ManagedBean' +modernApproach: '@Named + CDI' +summary: "用 CDI @Named 替代已废弃的 JSF @ManagedBean,实现统一的依赖注入模型。" +explanation: "JSF 的 @ManagedBean 和 @ManagedProperty 在 Jakarta Faces 4.0 中已废弃并移除。CDI @Named bean 提供相同的 EL 访问,并与整个 Jakarta EE 容器集成。" +whyModernWins: +- icon: 🔗 + title: 统一模型 + desc: "一个 CDI 容器管理所有 bean——JSF、REST 和服务层共享相同的依赖注入机制。" +- icon: 🔒 + title: 完整的 CDI 功能 + desc: "获得拦截器、装饰器、事件和所有 CDI 作用域。" +- icon: 🧪 + title: 更易测试 + desc: "普通 CDI bean,无需模拟 JSF ManagedBean 基础设施。" +support: + description: CDI @Named 自 Java EE 6 起可用;@ManagedBean 在 Jakarta Faces 4.0 中移除 diff --git a/translations/content/zh-CN/enterprise/manual-transaction-vs-declarative.yaml b/translations/content/zh-CN/enterprise/manual-transaction-vs-declarative.yaml new file mode 100644 index 0000000..900243d --- /dev/null +++ b/translations/content/zh-CN/enterprise/manual-transaction-vs-declarative.yaml @@ -0,0 +1,18 @@ +--- +title: 手动 JPA 事务与声明式 @Transactional +oldApproach: 手动事务 +modernApproach: '@Transactional' +summary: "用单个 @Transactional 注解替代冗长的 begin/commit/rollback 块。" +explanation: "手动事务管理需要显式的 begin()、commit() 和 rollback() 调用,通常包裹在 try/catch/finally 中。@Transactional 注解自动处理所有这些,包括异常时的回滚。" +whyModernWins: +- icon: 🗑️ + title: 无样板代码 + desc: "一个注解替代重复的 begin/commit/rollback try-catch 块。" +- icon: 🛡️ + title: 自动回滚 + desc: "未检查异常时自动回滚——无需手动 catch 块。" +- icon: 🔧 + title: 可配置 + desc: "传播、隔离、超时和只读通过注解属性控制。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/mdb-vs-reactive-messaging.yaml b/translations/content/zh-CN/enterprise/mdb-vs-reactive-messaging.yaml new file mode 100644 index 0000000..924bb92 --- /dev/null +++ b/translations/content/zh-CN/enterprise/mdb-vs-reactive-messaging.yaml @@ -0,0 +1,18 @@ +--- +title: Message-Driven Bean 与 Reactive Messaging +oldApproach: Message-Driven Bean +modernApproach: Reactive Messaging +summary: "用 MicroProfile Reactive Messaging 替代 JMS Message-Driven Bean,实现事件驱动处理。" +explanation: "Message-Driven Bean 需要实现 MessageListener,配置 @ActivationConfigProperty 并将所有内容包裹在 EJB 容器中。MicroProfile Reactive Messaging 只需一个 @Incoming 方法注解。" +whyModernWins: +- icon: 🪶 + title: 最少代码 + desc: "单个 @Incoming 方法替代 MDB 类、MessageListener 接口和 @ActivationConfigProperty。" +- icon: 🔀 + title: 多种消息系统 + desc: "相同的注解适用于 Kafka、AMQP、内存通道等。" +- icon: 🔗 + title: 响应式链 + desc: "轻松将 @Incoming 与 @Outgoing 链接以进行流处理。" +support: + description: 自 MicroProfile 4.0 / SmallRye Reactive Messaging 起可用 diff --git a/translations/content/zh-CN/enterprise/servlet-vs-jaxrs.yaml b/translations/content/zh-CN/enterprise/servlet-vs-jaxrs.yaml new file mode 100644 index 0000000..baf573e --- /dev/null +++ b/translations/content/zh-CN/enterprise/servlet-vs-jaxrs.yaml @@ -0,0 +1,18 @@ +--- +title: Servlet 与 JAX-RS +oldApproach: HttpServlet +modernApproach: JAX-RS Resource +summary: "用声明式 JAX-RS 资源类替代冗长的 HttpServlet 样板代码。" +explanation: "JAX-RS(Jakarta RESTful Web Services)允许您使用注解而非命令式 doGet/doPost 方法来暴露 REST 端点。路由、内容协商和参数绑定都是声明式的。" +whyModernWins: +- icon: 📐 + title: 声明式路由 + desc: "注解定义 HTTP 方法、路径和内容类型,而非命令式 switch 语句。" +- icon: 📏 + title: 更少代码 + desc: "50 行 Servlet 样板变为 15 行 JAX-RS 资源。" +- icon: 🔧 + title: 内置特性 + desc: "自动内容协商、参数绑定和异常映射。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/singleton-ejb-vs-cdi-application-scoped.yaml b/translations/content/zh-CN/enterprise/singleton-ejb-vs-cdi-application-scoped.yaml new file mode 100644 index 0000000..79ca1a9 --- /dev/null +++ b/translations/content/zh-CN/enterprise/singleton-ejb-vs-cdi-application-scoped.yaml @@ -0,0 +1,18 @@ +--- +title: Singleton EJB 与 CDI @ApplicationScoped +oldApproach: '@Singleton EJB' +modernApproach: '@ApplicationScoped CDI' +summary: "用 CDI @ApplicationScoped bean 替代 Singleton EJB,实现更简单的共享状态管理。" +explanation: "Singleton EJB 捆绑了并发管理(@Lock、@ConcurrencyManagement)和启动(@Startup)。CDI @ApplicationScoped 只需一个注解,将并发策略留给开发者。" +whyModernWins: +- icon: 🪶 + title: 减少注解噪音 + desc: "无需 @ConcurrencyManagement、@Lock 或 @Startup——只需一个 @ApplicationScoped。" +- icon: 🧪 + title: 更易测试 + desc: "普通 CDI bean,无需 EJB 容器的单例语义。" +- icon: 🔧 + title: 标准 CDI + desc: "与其他 CDI 特性(拦截器、事件)无缝配合。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/soap-vs-jakarta-rest.yaml b/translations/content/zh-CN/enterprise/soap-vs-jakarta-rest.yaml new file mode 100644 index 0000000..4c68ef0 --- /dev/null +++ b/translations/content/zh-CN/enterprise/soap-vs-jakarta-rest.yaml @@ -0,0 +1,18 @@ +--- +title: SOAP Web Services 与 Jakarta REST +oldApproach: JAX-WS / SOAP +modernApproach: Jakarta REST / JSON +summary: "用简洁的 Jakarta REST 资源和 JSON 替代重量级的 SOAP/WSDL 端点。" +explanation: "基于 SOAP 的 Web 服务依赖 WSDL 契约、XML 编组和重量级工具。Jakarta REST 使用简单的 HTTP 和 JSON,无需代码生成或 WSDL。" +whyModernWins: +- icon: 🪶 + title: 更轻的负载 + desc: "JSON 比 SOAP XML 信封更紧凑,减少带宽和解析开销。" +- icon: 🚀 + title: 无工具链 + desc: "无需 WSDL 生成、wsimport 或代码生成步骤。" +- icon: 🌐 + title: 更广泛的兼容性 + desc: "REST/JSON 可从任何语言或前端直接使用。" +support: + description: 自 Jakarta EE 8 / Java 11 起广泛可用 diff --git a/translations/content/zh-CN/enterprise/spring-api-versioning.yaml b/translations/content/zh-CN/enterprise/spring-api-versioning.yaml new file mode 100644 index 0000000..da8159b --- /dev/null +++ b/translations/content/zh-CN/enterprise/spring-api-versioning.yaml @@ -0,0 +1,18 @@ +--- +title: Spring Framework 7 API 版本控制 +oldApproach: 手动 URL 路径版本控制 +modernApproach: 原生 API 版本控制 +summary: "用 Spring Framework 7 的原生 API 版本控制支持替代重复的版本前缀控制器。" +explanation: "在 Spring Framework 7 之前,API 版本控制需要单独的控制器类(每个版本一个),或复杂的路径前缀配置。Spring 7 添加了原生版本控制,所有版本共存于同一个控制器类中。" +whyModernWins: +- icon: 🗂️ + title: 无控制器重复 + desc: "所有版本在一个控制器类中;只有各个处理方法按版本不同。" +- icon: 🔧 + title: 灵活版本策略 + desc: "支持基于 URL、标头和内容协商的版本控制。" +- icon: 🧹 + title: 集中版本逻辑 + desc: "版本配置集中于一处,易于维护。" +support: + description: 自 Spring Framework 7.0 起可用(需要 Java 17+) diff --git a/translations/content/zh-CN/enterprise/spring-null-safety-jspecify.yaml b/translations/content/zh-CN/enterprise/spring-null-safety-jspecify.yaml new file mode 100644 index 0000000..156ddf0 --- /dev/null +++ b/translations/content/zh-CN/enterprise/spring-null-safety-jspecify.yaml @@ -0,0 +1,18 @@ +--- +title: Spring Null 安全与 JSpecify +oldApproach: Spring @NonNull/@Nullable +modernApproach: JSpecify @NullMarked +summary: "Spring 7 采用 JSpecify 注解,将非 null 设为默认值,减少注解噪音。" +explanation: "Spring 5 和 6 在 org.springframework.lang 包中引入了自己的 null 安全注解。Spring 7 迁移到 JSpecify,使非 null 成为模块级默认值——只有可空的例外需要注解。" +whyModernWins: +- icon: ✂️ + title: 默认非 null + desc: "@NullMarked 使所有未注解类型非 null,只有可空异常需要标注。" +- icon: 🌐 + title: 供应商中立 + desc: "JSpecify 是跨框架的标准,不绑定于 Spring 特定注解。" +- icon: 🔧 + title: 工具集成 + desc: "IDE、分析器和 Kotlin 能够更好地理解 JSpecify 注解。" +support: + description: 自 Spring Framework 7.0 起可用(需要 Java 17+) diff --git a/translations/content/zh-CN/enterprise/spring-xml-config-vs-annotations.yaml b/translations/content/zh-CN/enterprise/spring-xml-config-vs-annotations.yaml new file mode 100644 index 0000000..938c64d --- /dev/null +++ b/translations/content/zh-CN/enterprise/spring-xml-config-vs-annotations.yaml @@ -0,0 +1,18 @@ +--- +title: Spring XML Bean 配置与注解驱动 +oldApproach: XML Bean 定义 +modernApproach: 注解驱动 Bean +summary: "用简洁的注解驱动配置替代冗长的 Spring XML bean 定义。" +explanation: "传统 Spring 应用通过 XML 配置文件连接 bean,需要大量重复的 定义。注解驱动配置(@Component、@Service、@Repository)消除了这些 XML。" +whyModernWins: +- icon: 🚫 + title: 无 XML + desc: "@SpringBootApplication 触发组件扫描和自动配置,消除 XML。" +- icon: 🔍 + title: 就近配置 + desc: "依赖项在类本身上声明,而非在外部 XML 中。" +- icon: 🧩 + title: 自动配置 + desc: "Spring Boot 自动配置基于 classpath 内容连接常用功能。" +support: + description: 自 Spring Boot 1.0 起广泛可用(2014 年 4 月);Spring Boot 3 需要 Java 17+ diff --git a/translations/content/zh-CN/errors/helpful-npe.yaml b/translations/content/zh-CN/errors/helpful-npe.yaml new file mode 100644 index 0000000..231e948 --- /dev/null +++ b/translations/content/zh-CN/errors/helpful-npe.yaml @@ -0,0 +1,18 @@ +--- +title: 有帮助的 NullPointerException +oldApproach: 晦涩的 NPE +modernApproach: 详细的 NPE +summary: "JVM 自动告诉您哪个变量为 null。" +explanation: "有帮助的 NPE 描述哪个表达式为 null 以及操作失败的原因。不再需要在链式方法调用中猜测哪个引用为 null。" +whyModernWins: +- icon: 🔍 + title: 精确变量 + desc: "消息在链中指出 null 变量的名称。" +- icon: ⚡ + title: 更快调试 + desc: "立即知道是哪个链中的引用为 null。" +- icon: 🆓 + title: 零代码更改 + desc: "JVM 自动生成消息,无需代码更改。" +support: + description: 自 JDK 14 起广泛可用(2020 年 3 月) diff --git a/translations/content/zh-CN/errors/multi-catch.yaml b/translations/content/zh-CN/errors/multi-catch.yaml new file mode 100644 index 0000000..889decd --- /dev/null +++ b/translations/content/zh-CN/errors/multi-catch.yaml @@ -0,0 +1,18 @@ +--- +title: 多异常捕获 +oldApproach: 单独的 catch 块 +modernApproach: 多重 catch +summary: "在单个 catch 块中捕获多种异常类型。" +explanation: "多重 catch 用相同的代码处理多种异常类型。异常变量是实际上 final 的,防止类型不安全的重新赋值。" +whyModernWins: +- icon: 📏 + title: DRY 原则 + desc: "相同的处理逻辑只写一次,而非三次。" +- icon: 🔒 + title: 类型安全 + desc: "捕获的异常是实际上 final 的——无法被重新赋值。" +- icon: 🧹 + title: 更少代码 + desc: "消除相同 catch 块的重复。" +support: + description: 自 JDK 7 起广泛可用(2011 年 7 月) diff --git a/translations/content/zh-CN/errors/null-in-switch.yaml b/translations/content/zh-CN/errors/null-in-switch.yaml new file mode 100644 index 0000000..4e5a057 --- /dev/null +++ b/translations/content/zh-CN/errors/null-in-switch.yaml @@ -0,0 +1,18 @@ +--- +title: switch 中的 null case +oldApproach: switch 前的守卫 +modernApproach: case null +summary: "直接将 null 作为 switch case 处理——无需单独的守卫。" +explanation: "模式匹配 switch 可以将 null 作为 case 标签匹配。这消除了在进入 switch 之前的单独 null 检查,使 null 处理在 switch 中清晰可见。" +whyModernWins: +- icon: 🎯 + title: 显式 + desc: "null 处理直接在 switch 中可见。" +- icon: 📏 + title: 更少代码 + desc: "无需在 switch 之前单独进行 null 检查。" +- icon: 🔒 + title: 防止 NPE + desc: "将 null 作为 case 处理,防止 NullPointerException。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/errors/optional-chaining.yaml b/translations/content/zh-CN/errors/optional-chaining.yaml new file mode 100644 index 0000000..70c50c3 --- /dev/null +++ b/translations/content/zh-CN/errors/optional-chaining.yaml @@ -0,0 +1,18 @@ +--- +title: Optional 链式调用 +oldApproach: 嵌套 null 检查 +modernApproach: Optional 管道 +summary: "用 Optional 管道替代嵌套 null 检查。" +explanation: "Optional.map() 透明地处理 null 值进行链式调用,在第一个 empty 时短路。这消除了嵌套的 if-null 检查,使正确路径清晰可见。" +whyModernWins: +- icon: 🔗 + title: 可链式调用 + desc: "每个 .map() 步骤透明地处理 null。" +- icon: 📖 + title: 快乐路径清晰 + desc: "正常流程线性可读,无嵌套。" +- icon: 🚫 + title: 无显式 null 检查 + desc: "null 处理内置于 Optional 的行为中。" +support: + description: 自 JDK 8+ 起可用(JDK 9+ 中有所改进) diff --git a/translations/content/zh-CN/errors/optional-orelsethrow.yaml b/translations/content/zh-CN/errors/optional-orelsethrow.yaml new file mode 100644 index 0000000..9c562b3 --- /dev/null +++ b/translations/content/zh-CN/errors/optional-orelsethrow.yaml @@ -0,0 +1,18 @@ +--- +title: 无 supplier 的 Optional.orElseThrow() +oldApproach: get() 或 orElseThrow(supplier) +modernApproach: orElseThrow() +summary: "使用 Optional.orElseThrow() 作为 get() 更清晰的、表达意图的替代方案。" +explanation: "Optional.get() 被广泛认为是代码异味,因为它隐藏了意外缺失值时会抛出异常的意图。orElseThrow() 让这一意图明确。" +whyModernWins: +- icon: 📖 + title: 自我描述 + desc: "orElseThrow() 清楚地表明缺失是意外情况。" +- icon: 🚫 + title: 无代码异味 + desc: "避免使用被认为不良实践的 get()。" +- icon: 🎯 + title: 意图明确 + desc: "与 get() 不同,名称传达了语义。" +support: + description: 自 JDK 10 起可用(2018 年 3 月)。 diff --git a/translations/content/zh-CN/errors/record-based-errors.yaml b/translations/content/zh-CN/errors/record-based-errors.yaml new file mode 100644 index 0000000..f03ff8f --- /dev/null +++ b/translations/content/zh-CN/errors/record-based-errors.yaml @@ -0,0 +1,18 @@ +--- +title: 基于 record 的错误响应 +oldApproach: Map 或冗长的类 +modernApproach: 错误 record +summary: "使用 record 定义简洁、不可变的错误响应类型。" +explanation: "record 非常适合错误响应——它们是不可变的,内置 equals/hashCode/toString,并且只需一行定义。非常适合 API 错误、验证结果和失败上下文。" +whyModernWins: +- icon: 📏 + title: 简洁 + desc: "用 3 行而非 30 行定义错误类型。" +- icon: 🔒 + title: 不可变 + desc: "错误响应在创建后无法修改。" +- icon: 🧩 + title: 可组合 + desc: "error record 可以嵌套并与模式匹配配合使用。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/errors/require-nonnull-else.yaml b/translations/content/zh-CN/errors/require-nonnull-else.yaml new file mode 100644 index 0000000..2aadc58 --- /dev/null +++ b/translations/content/zh-CN/errors/require-nonnull-else.yaml @@ -0,0 +1,18 @@ +--- +title: Objects.requireNonNullElse() +oldApproach: 三元 null 检查 +modernApproach: requireNonNullElse() +summary: "获取非 null 值并带有清晰的默认值,无需三元运算符。" +explanation: "requireNonNullElse 在第一个参数非 null 时返回它,否则返回默认值。与 Objects.requireNonNull() 不同,它不抛出异常——它提供回退值。" +whyModernWins: +- icon: 📖 + title: 意图清晰 + desc: "方法名准确描述其功能。" +- icon: 🛡️ + title: null 安全默认 + desc: "默认值本身不能为 null——这会抛出 NullPointerException。" +- icon: 📏 + title: 更简洁 + desc: "比三元 null 检查更简洁、更易读。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/io/deserialization-filters.yaml b/translations/content/zh-CN/io/deserialization-filters.yaml new file mode 100644 index 0000000..204d397 --- /dev/null +++ b/translations/content/zh-CN/io/deserialization-filters.yaml @@ -0,0 +1,18 @@ +--- +title: 反序列化过滤器 +oldApproach: 接受所有内容 +modernApproach: ObjectInputFilter +summary: "限制哪些类可以被反序列化,以防止攻击。" +explanation: "ObjectInputFilter 允许您对类进行白名单/黑名单管理,限制对象图深度、数组大小和总字节数。这保护应用程序免受反序列化攻击。" +whyModernWins: +- icon: 🛡️ + title: 安全性 + desc: "防止反序列化意外或恶意的类。" +- icon: 📏 + title: 粒度控制 + desc: "按类名、包、深度和大小过滤。" +- icon: 🔧 + title: 全局或每流 + desc: "在 JVM 级别或每个 ObjectInputStream 设置过滤器。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/io/file-memory-mapping.yaml b/translations/content/zh-CN/io/file-memory-mapping.yaml new file mode 100644 index 0000000..27d5cb2 --- /dev/null +++ b/translations/content/zh-CN/io/file-memory-mapping.yaml @@ -0,0 +1,18 @@ +--- +title: 文件内存映射 +oldApproach: MappedByteBuffer +modernApproach: 使用 Arena 的 MemorySegment +summary: "使用 MemorySegment 映射大于 2GB 的文件,支持确定性清理。" +explanation: "外部函数与内存 API(JEP 454)引入了带有 Arena 的 MemorySegment,解决了 MappedByteBuffer 的两个主要限制:2GB 大小限制和缺乏确定性清理。" +whyModernWins: +- icon: 📏 + title: 无大小限制 + desc: "无需变通方案即可映射大于 2GB 的文件。" +- icon: 🧹 + title: 确定性清理 + desc: "Arena 关闭时内存立即释放。" +- icon: 🔒 + title: 更安全的 API + desc: "MemorySegment 相比 ByteBuffer 提供更强的内存安全保证。" +support: + description: 自 JDK 22 起可用(2024 年 3 月) diff --git a/translations/content/zh-CN/io/files-mismatch.yaml b/translations/content/zh-CN/io/files-mismatch.yaml new file mode 100644 index 0000000..768e3dd --- /dev/null +++ b/translations/content/zh-CN/io/files-mismatch.yaml @@ -0,0 +1,18 @@ +--- +title: Files.mismatch() +oldApproach: 手动字节比较 +modernApproach: Files.mismatch() +summary: "高效比较两个文件,无需将其加载到内存中。" +explanation: "Files.mismatch() 返回第一个字节差异的位置,如果文件相同则返回 -1。它不将文件加载到内存,效率比手动字节数组比较高得多。" +whyModernWins: +- icon: ⚡ + title: 内存高效 + desc: "不将整个文件加载到字节数组中。" +- icon: 📏 + title: 简洁 + desc: "一行替代复杂的手动比较循环。" +- icon: 🎯 + title: 差异位置 + desc: "返回差异的确切字节偏移量。" +support: + description: 自 JDK 12 起广泛可用(2019 年 3 月) diff --git a/translations/content/zh-CN/io/http-client.yaml b/translations/content/zh-CN/io/http-client.yaml new file mode 100644 index 0000000..79c1b06 --- /dev/null +++ b/translations/content/zh-CN/io/http-client.yaml @@ -0,0 +1,18 @@ +--- +title: 现代 HTTP 客户端 +oldApproach: HttpURLConnection +modernApproach: HttpClient +summary: "使用内置 HttpClient 发出简洁、现代的 HTTP 请求。" +explanation: "HttpClient 支持 HTTP/1.1 和 HTTP/2、异步请求、WebSocket 以及请求/响应的 BodyHandler。与 HttpURLConnection 相比,它是一个重大改进。" +whyModernWins: +- icon: 📐 + title: 构建器 API + desc: "用于请求、标头和超时的流畅构建器。" +- icon: ⚡ + title: 异步支持 + desc: "sendAsync() 返回 CompletableFuture,无需阻塞。" +- icon: 🔒 + title: HTTP/2 支持 + desc: "开箱即用支持 HTTP/2 和 TLS。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/io/inputstream-transferto.yaml b/translations/content/zh-CN/io/inputstream-transferto.yaml new file mode 100644 index 0000000..34484c8 --- /dev/null +++ b/translations/content/zh-CN/io/inputstream-transferto.yaml @@ -0,0 +1,18 @@ +--- +title: InputStream.transferTo() +oldApproach: 手动复制循环 +modernApproach: transferTo() +summary: "一次调用将 InputStream 复制到 OutputStream。" +explanation: "transferTo() 从输入流读取所有字节并写入输出流。内部使用高效的缓冲区,无需手动分配缓冲区数组或循环。" +whyModernWins: +- icon: 📏 + title: 一行代码 + desc: "用一次方法调用替代整个读写循环。" +- icon: 🧹 + title: 无手动缓冲区 + desc: "不需要 byte[] buffer 或循环计数器。" +- icon: 🛡️ + title: 正确处理 + desc: "正确处理部分读取和流结束。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/io/io-class-console-io.yaml b/translations/content/zh-CN/io/io-class-console-io.yaml new file mode 100644 index 0000000..4c497fd --- /dev/null +++ b/translations/content/zh-CN/io/io-class-console-io.yaml @@ -0,0 +1,18 @@ +--- +title: 用于控制台 I/O 的 IO 类 +oldApproach: System.out / Scanner +modernApproach: IO 类 +summary: "新的 IO 类为控制台输入和输出提供简单、简洁的方法。" +explanation: "Java 25 引入了 IO 类(java.io.IO),作为隐式声明类的一部分。它提供 println()、print() 和 readln() 方法,无需导入或 Scanner 设置。" +whyModernWins: +- icon: ✨ + title: 极度简化 + desc: "两个方法替代七行 Scanner 设置、提示、读取和关闭代码。" +- icon: 🎓 + title: 对初学者友好 + desc: "标准 I/O 无需样板代码。" +- icon: 🧹 + title: 零导入 + desc: "在隐式声明类中无需导入 IO。" +support: + description: JDK 25 预览版,作为隐式声明类的一部分(JEP 495) diff --git a/translations/content/zh-CN/io/path-of.yaml b/translations/content/zh-CN/io/path-of.yaml new file mode 100644 index 0000000..44e824c --- /dev/null +++ b/translations/content/zh-CN/io/path-of.yaml @@ -0,0 +1,18 @@ +--- +title: Path.of() 工厂方法 +oldApproach: Paths.get() +modernApproach: Path.of() +summary: "使用 Path.of()——Path 接口上的现代工厂方法。" +explanation: "Path.of() 是直接添加到 Path 接口的工厂方法,遵循与 List.of()、Set.of() 相同的模式。Paths.get() 现在已过时但仍然有效。" +whyModernWins: +- icon: 📐 + title: 一致的 API + desc: "遵循 .of() 工厂模式,如 List.of()、Set.of()。" +- icon: 📖 + title: 更清晰的意图 + desc: "Path.of() 读起来比 Paths.get() 更自然。" +- icon: 🔧 + title: 相同功能 + desc: "零迁移成本——行为完全相同。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/io/reading-files.yaml b/translations/content/zh-CN/io/reading-files.yaml new file mode 100644 index 0000000..5d0afaf --- /dev/null +++ b/translations/content/zh-CN/io/reading-files.yaml @@ -0,0 +1,18 @@ +--- +title: 读取文件 +oldApproach: BufferedReader +modernApproach: Files.readString() +summary: "用一行代码将整个文件读入 String。" +explanation: "Files.readString() 将文件的全部内容读入 String。它处理编码(默认 UTF-8)并管理文件关闭——不需要 BufferedReader 样板代码。" +whyModernWins: +- icon: 📏 + title: 一行代码 + desc: "替代 8 行 BufferedReader 样板代码。" +- icon: 🧹 + title: 自动关闭 + desc: "文件自动关闭——无需 try-with-resources。" +- icon: 🌐 + title: 编码控制 + desc: "可选的 Charset 参数,默认为 UTF-8。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/io/try-with-resources-effectively-final.yaml b/translations/content/zh-CN/io/try-with-resources-effectively-final.yaml new file mode 100644 index 0000000..6266708 --- /dev/null +++ b/translations/content/zh-CN/io/try-with-resources-effectively-final.yaml @@ -0,0 +1,18 @@ +--- +title: try-with-resources 改进 +oldApproach: 重新声明变量 +modernApproach: 实际上 final +summary: "直接在 try-with-resources 中使用现有的实际上 final 变量。" +explanation: "Java 9 允许在 try-with-resources 中直接使用实际上 final 的变量,无需重新声明新变量。当资源在 try 块之外创建时,这减少了冗余。" +whyModernWins: +- icon: 🧹 + title: 无重新声明 + desc: "直接使用现有变量名。" +- icon: 📏 + title: 更少代码 + desc: "消除冗余的本地变量声明。" +- icon: 📖 + title: 更清晰 + desc: "try 块中更少的变量混淆作用域。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/io/writing-files.yaml b/translations/content/zh-CN/io/writing-files.yaml new file mode 100644 index 0000000..2928ba8 --- /dev/null +++ b/translations/content/zh-CN/io/writing-files.yaml @@ -0,0 +1,18 @@ +--- +title: 写入文件 +oldApproach: FileWriter + BufferedWriter +modernApproach: Files.writeString() +summary: "用一行代码将 String 写入文件。" +explanation: "Files.writeString() 默认使用 UTF-8 编码将内容写入文件。它处理文件创建和关闭——不需要 FileWriter 或 BufferedWriter 包装。" +whyModernWins: +- icon: 📏 + title: 一行代码 + desc: "无需 writer 包装或 try-with-resources。" +- icon: 🧹 + title: 自动关闭 + desc: "文件自动关闭。" +- icon: 🔧 + title: OpenOption 支持 + desc: "传递 StandardOpenOptions.APPEND 等选项控制行为。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/language/compact-canonical-constructor.yaml b/translations/content/zh-CN/language/compact-canonical-constructor.yaml new file mode 100644 index 0000000..def11d9 --- /dev/null +++ b/translations/content/zh-CN/language/compact-canonical-constructor.yaml @@ -0,0 +1,18 @@ +--- +title: 紧凑规范构造函数 +oldApproach: 显式构造函数验证 +modernApproach: 紧凑构造函数 +summary: "无需重复参数列表即可验证和规范化 record 字段。" +explanation: "record 可以声明一个省略参数列表的紧凑规范构造函数。编译器在函数体执行后自动将所有参数赋值给对应字段。" +whyModernWins: +- icon: ✂️ + title: 减少重复 + desc: "无需重复参数列表或手动赋值每个字段。" +- icon: 🛡️ + title: 验证 + desc: "非常适合 null 检查、范围验证和防御性复制。" +- icon: 📖 + title: 意图更清晰 + desc: "紧凑语法强调验证逻辑,而非样板代码。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/language/compact-source-files.yaml b/translations/content/zh-CN/language/compact-source-files.yaml new file mode 100644 index 0000000..5013411 --- /dev/null +++ b/translations/content/zh-CN/language/compact-source-files.yaml @@ -0,0 +1,18 @@ +--- +title: 紧凑源文件 +oldApproach: 主类样板 +modernApproach: void main() +summary: "无需类声明或 public static void main 即可编写完整程序。" +explanation: "紧凑源文件去除了类声明和 public static void main 签名的仪式感。顶层的 void main() 足以运行一个程序。" +whyModernWins: +- icon: 🚀 + title: 零仪式 + desc: "无需 class、无需 public static void main、无需 String[] args。" +- icon: 🎓 + title: 对初学者友好 + desc: "新程序员从第一行就能编写有用的代码。" +- icon: 📝 + title: 脚本风格 + desc: "非常适合快速原型、脚本和示例。" +support: + description: 在 JDK 25 LTS 中正式发布(JEP 512,2025 年 9 月)。 diff --git a/translations/content/zh-CN/language/default-interface-methods.yaml b/translations/content/zh-CN/language/default-interface-methods.yaml new file mode 100644 index 0000000..b4d3267 --- /dev/null +++ b/translations/content/zh-CN/language/default-interface-methods.yaml @@ -0,0 +1,18 @@ +--- +title: 接口默认方法 +oldApproach: 用抽象类共享行为 +modernApproach: 接口上的默认方法 +summary: "直接在接口中添加方法实现,支持行为的多重继承。" +explanation: "Java 8 之前,跨不相关类共享行为需要抽象基类,这限制了灵活性。默认方法允许接口在不破坏现有实现的情况下进行演进。" +whyModernWins: +- icon: 🔀 + title: 多重继承 + desc: "类可以实现多个带有默认方法的接口,不像单继承的抽象类那样受限。" +- icon: 📦 + title: API 演进 + desc: "向接口添加新方法而不破坏现有实现。" +- icon: 🧩 + title: 可组合行为 + desc: "自由混合和匹配来自多个接口的功能。" +support: + description: 自 JDK 8 起可用(2014 年 3 月)。 diff --git a/translations/content/zh-CN/language/diamond-operator.yaml b/translations/content/zh-CN/language/diamond-operator.yaml new file mode 100644 index 0000000..bdd37c3 --- /dev/null +++ b/translations/content/zh-CN/language/diamond-operator.yaml @@ -0,0 +1,18 @@ +--- +title: 匿名类的菱形运算符 +oldApproach: 重复类型参数 +modernApproach: 菱形运算符 <> +summary: "菱形运算符现在也适用于匿名类。" +explanation: "Java 7 引入了 <> 但不适用于匿名内部类。Java 9 解除了这一限制,使菱形运算符可以在任何地方使用。" +whyModernWins: +- icon: 📏 + title: 一致的规则 + desc: "菱形运算符无处不在——构造函数和匿名类均适用。" +- icon: 🧹 + title: 减少冗余 + desc: "类型参数在左侧声明一次,不再重复。" +- icon: 🔧 + title: DRY 原则 + desc: "编译器已经知道类型——为什么要写两遍?" +support: + description: 匿名类的菱形运算符自 JDK 9 起可用(2017 年 9 月)。 diff --git a/translations/content/zh-CN/language/exhaustive-switch.yaml b/translations/content/zh-CN/language/exhaustive-switch.yaml new file mode 100644 index 0000000..748afa2 --- /dev/null +++ b/translations/content/zh-CN/language/exhaustive-switch.yaml @@ -0,0 +1,18 @@ +--- +title: 无 default 的穷举 switch +oldApproach: 强制 default 分支 +modernApproach: 密封类穷举性 +summary: "编译器验证所有密封子类型均已覆盖——无需 default 分支。" +explanation: "对密封类型进行 switch 时,编译器在编译时知道所有可能的子类型。如果所有情况均已覆盖,则不需要 default 分支。" +whyModernWins: +- icon: ✅ + title: 编译时安全 + desc: "添加新子类型时,编译器会显示每个需要更新的地方。" +- icon: 🚫 + title: 无死代码 + desc: "没有掩盖 bug 的不可达 default 分支。" +- icon: 📐 + title: 代数类型 + desc: "密封类 + record + 穷举 switch = Java 中的正式 ADT。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/language/flexible-constructor-bodies.yaml b/translations/content/zh-CN/language/flexible-constructor-bodies.yaml new file mode 100644 index 0000000..ee96ce9 --- /dev/null +++ b/translations/content/zh-CN/language/flexible-constructor-bodies.yaml @@ -0,0 +1,18 @@ +--- +title: 灵活的构造函数体 +oldApproach: 在 super() 之后验证 +modernApproach: 在 super() 之前编写代码 +summary: "在调用 super() 或 this() 之前验证和计算值。" +explanation: "Java 25 解除了 super() 必须是第一条语句的限制。现在可以在超类构造函数运行之前验证参数、计算派生值并准备数据。" +whyModernWins: +- icon: 🛡️ + title: 快速失败 + desc: "在超类构造函数运行之前验证参数。" +- icon: 🧮 + title: 预先计算 + desc: "在调用 super() 之前派生值并准备数据。" +- icon: 🧹 + title: 无变通方案 + desc: "不再需要静态辅助方法或工厂模式来绕过该限制。" +support: + description: 在 JDK 25 LTS 中正式发布(JEP 513,2025 年 9 月)。 diff --git a/translations/content/zh-CN/language/guarded-patterns.yaml b/translations/content/zh-CN/language/guarded-patterns.yaml new file mode 100644 index 0000000..1a96b37 --- /dev/null +++ b/translations/content/zh-CN/language/guarded-patterns.yaml @@ -0,0 +1,18 @@ +--- +title: 带 when 的守卫模式 +oldApproach: 嵌套 if +modernApproach: when 子句 +summary: "使用 when 守卫向模式 case 添加条件。" +explanation: "守卫模式让您使用 when 关键字通过额外的布尔条件来细化类型匹配。这替代了 switch 分支内的嵌套 if/else。" +whyModernWins: +- icon: 🎯 + title: 精确匹配 + desc: "在单个 case 标签中组合类型和条件。" +- icon: 📐 + title: 扁平结构 + desc: "switch case 内无嵌套 if/else。" +- icon: 📖 + title: 可读意图 + desc: "when 子句读起来像自然语言。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/language/markdown-javadoc-comments.yaml b/translations/content/zh-CN/language/markdown-javadoc-comments.yaml new file mode 100644 index 0000000..cc82a1b --- /dev/null +++ b/translations/content/zh-CN/language/markdown-javadoc-comments.yaml @@ -0,0 +1,18 @@ +--- +title: Javadoc 注释中的 Markdown +oldApproach: 基于 HTML 的 Javadoc +modernApproach: Markdown Javadoc +summary: "用 Markdown 而非 HTML 编写 Javadoc 注释,提高可读性。" +explanation: "Java 23 引入了 /// Markdown 风格的 Javadoc 注释,作为 /** HTML Javadoc 的替代方案。它们在生成的 HTML 文档中正确渲染。" +whyModernWins: +- icon: 📖 + title: 自然语法 + desc: "使用反引号表示行内代码,使用 ``` 表示代码块,而非 HTML 标签。" +- icon: ✍️ + title: 更易编写 + desc: '无需 {@code}、

标签——直接编写 Markdown。' +- icon: 👁 + title: 编辑器中更美观 + desc: "Markdown 在现代 IDE 和文本编辑器中渲染效果极佳。" +support: + description: 自 JDK 23 起可用(2024 年 9 月) diff --git a/translations/content/zh-CN/language/module-import-declarations.yaml b/translations/content/zh-CN/language/module-import-declarations.yaml new file mode 100644 index 0000000..d885806 --- /dev/null +++ b/translations/content/zh-CN/language/module-import-declarations.yaml @@ -0,0 +1,18 @@ +--- +title: 模块导入声明 +oldApproach: 大量 import 语句 +modernApproach: import module +summary: "用单个声明导入模块导出的所有包。" +explanation: "模块导入声明让您用单个 import module 语句导入模块导出的所有内容,替代大量单独的包导入。" +whyModernWins: +- icon: 🧹 + title: 一行搞定 + desc: "用单个模块导入替代大量 import 语句。" +- icon: 📦 + title: 模块感知 + desc: "利用模块系统导入一致的包集合。" +- icon: 🚀 + title: 快速启动 + desc: "非常适合脚本和原型,无需繁琐的 import 列表。" +support: + description: 在 JDK 25 LTS 中正式发布(JEP 511,2025 年 9 月)。 diff --git a/translations/content/zh-CN/language/pattern-matching-instanceof.yaml b/translations/content/zh-CN/language/pattern-matching-instanceof.yaml new file mode 100644 index 0000000..0bfc6c6 --- /dev/null +++ b/translations/content/zh-CN/language/pattern-matching-instanceof.yaml @@ -0,0 +1,18 @@ +--- +title: instanceof 的模式匹配 +oldApproach: instanceof + 强制类型转换 +modernApproach: 模式变量 +summary: "通过模式匹配在一步中组合类型检查和转换。" +explanation: "instanceof 的模式匹配消除了 instanceof 检查后冗余的类型转换。绑定变量自动具有正确的类型和作用域。" +whyModernWins: +- icon: 🔄 + title: 无冗余转换 + desc: "类型检查和变量绑定在单个表达式中完成。" +- icon: 📏 + title: 更少代码行 + desc: "一行代替两行——转换行完全消失。" +- icon: 🛡️ + title: 作用域安全 + desc: "模式变量仅在保证类型正确的作用域内有效。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/language/pattern-matching-switch.yaml b/translations/content/zh-CN/language/pattern-matching-switch.yaml new file mode 100644 index 0000000..2f1b869 --- /dev/null +++ b/translations/content/zh-CN/language/pattern-matching-switch.yaml @@ -0,0 +1,18 @@ +--- +title: switch 中的模式匹配 +oldApproach: if-else 链 +modernApproach: 类型模式 +summary: "用简洁的 switch 类型模式替代 if-else instanceof 链。" +explanation: "switch 中的模式匹配让您直接匹配类型,在单个 case 标签中组合类型检查、转换和绑定。" +whyModernWins: +- icon: 📐 + title: 结构化分派 + desc: "switch 使分支结构清晰可见且易于扫描。" +- icon: 🎯 + title: 表达式形式 + desc: "直接返回值——无需可变临时变量。" +- icon: ✅ + title: 穷举性 + desc: "编译器确保所有类型均已处理。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/language/primitive-types-in-patterns.yaml b/translations/content/zh-CN/language/primitive-types-in-patterns.yaml new file mode 100644 index 0000000..6dddb82 --- /dev/null +++ b/translations/content/zh-CN/language/primitive-types-in-patterns.yaml @@ -0,0 +1,18 @@ +--- +title: 模式中的原始类型 +oldApproach: 手动范围检查 +modernApproach: 原始类型模式 +summary: "模式匹配现在适用于原始类型,不仅限于对象。" +explanation: "Java 25 将模式匹配扩展到原始类型。您可以在 instanceof 和 switch 中使用 int、long、double 等作为模式变量。" +whyModernWins: +- icon: 📦 + title: 无装箱 + desc: "直接匹配原始类型——无需 Integer 包装器。" +- icon: 🎯 + title: 模式一致性 + desc: "对象和原始类型使用相同的模式语法。" +- icon: ⚡ + title: 更好的性能 + desc: "避免模式匹配中的自动装箱开销。" +support: + description: JDK 25 预览版(第三次预览,JEP 507)。需要 --enable-preview。 diff --git a/translations/content/zh-CN/language/private-interface-methods.yaml b/translations/content/zh-CN/language/private-interface-methods.yaml new file mode 100644 index 0000000..0d48f8d --- /dev/null +++ b/translations/content/zh-CN/language/private-interface-methods.yaml @@ -0,0 +1,18 @@ +--- +title: 接口私有方法 +oldApproach: 重复逻辑 +modernApproach: 私有方法 +summary: "使用私有方法提取接口中的共享逻辑。" +explanation: "Java 9 允许在接口中使用私有方法,使您可以在默认方法之间共享代码,而不向实现类暴露实现细节。" +whyModernWins: +- icon: 🧩 + title: 代码复用 + desc: "在默认方法之间共享逻辑,避免重复。" +- icon: 🔐 + title: 封装 + desc: "实现细节对实现类保持隐藏。" +- icon: 🧹 + title: DRY 接口 + desc: "不再需要在默认方法之间复制粘贴。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/language/record-patterns.yaml b/translations/content/zh-CN/language/record-patterns.yaml new file mode 100644 index 0000000..f5cd23c --- /dev/null +++ b/translations/content/zh-CN/language/record-patterns.yaml @@ -0,0 +1,18 @@ +--- +title: record 模式(解构) +oldApproach: 手动访问 +modernApproach: 解构 +summary: "直接在模式中解构 record——一步提取字段。" +explanation: "record 模式让您在 instanceof 和 switch 模式中直接分解 record 的组件。组件在单个表达式中绑定到变量。" +whyModernWins: +- icon: 🎯 + title: 直接提取 + desc: "无需手动调用访问器即可访问 record 组件。" +- icon: 🪆 + title: 可嵌套 + desc: "模式可以嵌套——在单个表达式中匹配内部 record。" +- icon: 📏 + title: 代码紧凑 + desc: "五行变两行——减少仪式感,保持清晰。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/language/records-for-data-classes.yaml b/translations/content/zh-CN/language/records-for-data-classes.yaml new file mode 100644 index 0000000..05eac51 --- /dev/null +++ b/translations/content/zh-CN/language/records-for-data-classes.yaml @@ -0,0 +1,18 @@ +--- +title: 用 record 定义数据类 +oldApproach: 冗长的 POJO +modernApproach: record +summary: "一行代码替代不可变数据载体的 30 多行样板代码。" +explanation: "record 自动从组件列表生成构造函数、访问器(x()、y())、equals()、hashCode() 和 toString()。" +whyModernWins: +- icon: ⚡ + title: 一行定义 + desc: "单行代码替代构造函数、getter、equals、hashCode、toString。" +- icon: 🔒 + title: 默认不可变 + desc: "所有字段均为 final——没有 setter 的隐患。" +- icon: 🧩 + title: 模式友好 + desc: "record 可与 switch 和 instanceof 中的解构模式配合使用。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/language/sealed-classes.yaml b/translations/content/zh-CN/language/sealed-classes.yaml new file mode 100644 index 0000000..439bbd1 --- /dev/null +++ b/translations/content/zh-CN/language/sealed-classes.yaml @@ -0,0 +1,18 @@ +--- +title: 用密封类定义类型层次 +oldApproach: 开放层次 +modernApproach: sealed permits +summary: "限制哪些类可以扩展某个类型——支持穷举 switch。" +explanation: "密封类定义了一组封闭的子类型。编译器在编译时知道所有可能的子类型,从而支持穷举 switch 表达式。" +whyModernWins: +- icon: 🔐 + title: 受控层次 + desc: "只有允许的子类型可以扩展——没有意外子类。" +- icon: ✅ + title: 穷举匹配 + desc: "编译器验证 switch 覆盖所有情况,无需 default。" +- icon: 📐 + title: 代数数据类型 + desc: "自然建模求和类型——密封类 + record = Java 中的 ADT。" +support: + description: 自 JDK 17 LTS 起广泛可用(2021 年 9 月) diff --git a/translations/content/zh-CN/language/static-members-in-inner-classes.yaml b/translations/content/zh-CN/language/static-members-in-inner-classes.yaml new file mode 100644 index 0000000..58ab9ee --- /dev/null +++ b/translations/content/zh-CN/language/static-members-in-inner-classes.yaml @@ -0,0 +1,18 @@ +--- +title: 内部类中的静态成员 +oldApproach: 必须使用静态嵌套类 +modernApproach: 内部类中的静态成员 +summary: "在内部类中定义静态成员,无需使用静态嵌套类。" +explanation: "Java 16 之前,只有静态嵌套类才能包含静态成员。Java 16 解除了这一限制,允许内部类声明静态字段和方法。" +whyModernWins: +- icon: 🔓 + title: 更大灵活性 + desc: "内部类现在可以在需要时拥有静态成员。" +- icon: 🧩 + title: 共享状态 + desc: "跨内部类实例追踪共享状态。" +- icon: 📐 + title: 设计自由 + desc: "无需仅为一个静态字段而将类提升为静态嵌套类。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/language/static-methods-in-interfaces.yaml b/translations/content/zh-CN/language/static-methods-in-interfaces.yaml new file mode 100644 index 0000000..7c79de9 --- /dev/null +++ b/translations/content/zh-CN/language/static-methods-in-interfaces.yaml @@ -0,0 +1,18 @@ +--- +title: 接口中的静态方法 +oldApproach: 工具类 +modernApproach: 接口静态方法 +summary: "直接在接口中添加静态工具方法,而非单独的工具类。" +explanation: "Java 8 之前,与接口相关的工具方法必须放在配套的工具类中。接口上的静态方法将相关 API 聚合在一起。" +whyModernWins: +- icon: 📦 + title: 更好的组织 + desc: "将相关工具方法与接口放在一起,而非单独的类中。" +- icon: 🔍 + title: 可发现性 + desc: "工厂和辅助方法在您期望的地方找到。" +- icon: 🧩 + title: API 内聚性 + desc: "无需单独的 *Utils 或 *Helper 类。" +support: + description: 自 JDK 8 起可用(2014 年 3 月) diff --git a/translations/content/zh-CN/language/switch-expressions.yaml b/translations/content/zh-CN/language/switch-expressions.yaml new file mode 100644 index 0000000..81aba8b --- /dev/null +++ b/translations/content/zh-CN/language/switch-expressions.yaml @@ -0,0 +1,18 @@ +--- +title: switch 表达式 +oldApproach: switch 语句 +modernApproach: switch 表达式 +summary: "switch 作为返回值的表达式——无 break,无穿透。" +explanation: "switch 表达式直接返回值,使用箭头语法防止穿透,并要求穷举性。编译器检查所有情况是否已处理。" +whyModernWins: +- icon: 🎯 + title: 返回值 + desc: "直接赋值 switch 结果——无需临时变量。" +- icon: 🛡️ + title: 无穿透 + desc: "箭头语法消除因缺少 break 而导致的意外穿透 bug。" +- icon: ✅ + title: 穷举性检查 + desc: "编译器确保所有情况均已覆盖。" +support: + description: 自 JDK 14 起广泛可用(2020 年 3 月) diff --git a/translations/content/zh-CN/language/text-blocks-for-multiline-strings.yaml b/translations/content/zh-CN/language/text-blocks-for-multiline-strings.yaml new file mode 100644 index 0000000..e74985c --- /dev/null +++ b/translations/content/zh-CN/language/text-blocks-for-multiline-strings.yaml @@ -0,0 +1,18 @@ +--- +title: 多行字符串文本块 +oldApproach: 字符串拼接 +modernApproach: 文本块 +summary: "使用三引号文本块自然地编写多行字符串。" +explanation: "文本块让您以原始形式编写多行字符串。无需拼接,无需对嵌入引号进行转义,并自动去除缩进。" +whyModernWins: +- icon: 📖 + title: 所见即所得 + desc: "JSON、SQL 和 HTML 在源码中就像真正的 JSON、SQL 和 HTML。" +- icon: 🚫 + title: 无转义地狱 + desc: "嵌入的引号无需反斜杠转义。" +- icon: 📐 + title: 智能缩进 + desc: "根据结束分隔符的位置自动去除前导空白。" +support: + description: 自 JDK 15 起广泛可用(2020 年 9 月) diff --git a/translations/content/zh-CN/language/type-inference-with-var.yaml b/translations/content/zh-CN/language/type-inference-with-var.yaml new file mode 100644 index 0000000..f4a89c6 --- /dev/null +++ b/translations/content/zh-CN/language/type-inference-with-var.yaml @@ -0,0 +1,18 @@ +--- +title: 使用 var 进行类型推断 +oldApproach: 显式类型声明 +modernApproach: var 关键字 +summary: "使用 var 进行局部变量类型推断——减少噪音,同样安全。" +explanation: "自 Java 10 起,编译器从右侧表达式推断局部变量类型。这在不牺牲类型安全的情况下减少了视觉噪音。当类型从上下文中显而易见时,使用 var。" +whyModernWins: +- icon: ⚡ + title: 减少样板代码 + desc: "无需在赋值两侧重复复杂的泛型类型。" +- icon: 👁 + title: 提高可读性 + desc: "专注于变量名和值,而非类型声明。" +- icon: 🔒 + title: 仍然类型安全 + desc: 编译器在编译时推断并强制执行确切类型。 +support: + description: 自 JDK 10 起广泛可用(2018 年 3 月) diff --git a/translations/content/zh-CN/language/unnamed-variables.yaml b/translations/content/zh-CN/language/unnamed-variables.yaml new file mode 100644 index 0000000..097be37 --- /dev/null +++ b/translations/content/zh-CN/language/unnamed-variables.yaml @@ -0,0 +1,18 @@ +--- +title: 用 _ 表示未命名变量 +oldApproach: 未使用变量 +modernApproach: _ 占位符 +summary: "使用 _ 表示变量被有意忽略的意图。" +explanation: "未命名变量向读者和工具传达一个值被刻意忽略的信息。下划线在 Java 22+ 中是保留标识符。" +whyModernWins: +- icon: 📢 + title: 意图清晰 + desc: '_ 明确表示"此处不需要这个值"。' +- icon: 🔇 + title: 无警告 + desc: "IDE 和 linter 不会标记有意未使用的变量。" +- icon: 🧹 + title: 更简洁的 lambda + desc: "当只需要部分参数时,多参数 lambda 更简洁。" +support: + description: 在 JDK 22 中正式发布(JEP 456,2024 年 3 月)。 diff --git a/translations/content/zh-CN/security/key-derivation-functions.yaml b/translations/content/zh-CN/security/key-derivation-functions.yaml new file mode 100644 index 0000000..aa12a91 --- /dev/null +++ b/translations/content/zh-CN/security/key-derivation-functions.yaml @@ -0,0 +1,18 @@ +--- +title: 密钥派生函数 +oldApproach: 手动 PBKDF2 +modernApproach: KDF API +summary: "使用标准 KDF API 派生加密密钥。" +explanation: "KDF API 为密钥派生函数(如 HKDF 和 PBKDF2)提供标准接口。它使用构建器模式替代笨拙的 KeySpec 构造函数,使密钥派生更加清晰且不易出错。" +whyModernWins: +- icon: 📐 + title: 简洁的 API + desc: "构建器模式替代笨拙的 KeySpec 构造函数。" +- icon: 🔒 + title: 标准接口 + desc: "一致的 API 适用于不同的 KDF 算法。" +- icon: 🛡️ + title: 更少错误 + desc: "类型安全的构建器减少参数顺序错误的风险。" +support: + description: 在 JDK 25 LTS 中正式发布(JEP 510,2025 年 9 月)。 diff --git a/translations/content/zh-CN/security/pem-encoding.yaml b/translations/content/zh-CN/security/pem-encoding.yaml new file mode 100644 index 0000000..f31a26d --- /dev/null +++ b/translations/content/zh-CN/security/pem-encoding.yaml @@ -0,0 +1,18 @@ +--- +title: PEM 编码/解码 +oldApproach: 手动 Base64 + 标头 +modernApproach: PEM API +summary: "原生编码和解码 PEM 格式的加密对象。" +explanation: "PEM API 为证书、密钥、CSR 等提供标准编码/解码。不再需要手动处理 Base64 编码、PEM 标头和行换行。" +whyModernWins: +- icon: 🧹 + title: 无手动 Base64 + desc: "PEM 标头、行换行和 Base64 自动处理。" +- icon: 📐 + title: 标准格式 + desc: "符合 RFC 7468 的 PEM 编码。" +- icon: 🔒 + title: 类型安全 + desc: "按类型解码——证书、私钥、公钥等。" +support: + description: JDK 25 预览版(JEP 470)。需要 --enable-preview。 diff --git a/translations/content/zh-CN/security/random-generator.yaml b/translations/content/zh-CN/security/random-generator.yaml new file mode 100644 index 0000000..4cefaa9 --- /dev/null +++ b/translations/content/zh-CN/security/random-generator.yaml @@ -0,0 +1,18 @@ +--- +title: RandomGenerator 接口 +oldApproach: new Random() / ThreadLocalRandom +modernApproach: RandomGenerator 工厂 +summary: "使用 RandomGenerator 接口按名称选择随机数算法。" +explanation: "JDK 17 引入 RandomGenerator 作为所有 RNG 实现的通用接口。通过名称选择算法,可以轻松切换实现而无需更改代码结构。" +whyModernWins: +- icon: 🔧 + title: 算法无关 + desc: "按名称选择最佳 RNG 算法,无需更改代码结构。" +- icon: 📐 + title: 统一接口 + desc: "所有随机数生成器共享相同的接口。" +- icon: ⚡ + title: 更好的算法 + desc: "访问 L64X128MixRandom 等现代高质量 PRNG。" +support: + description: 自 JDK 17 起可用(2021 年 9 月,JEP 356)。 diff --git a/translations/content/zh-CN/security/strong-random.yaml b/translations/content/zh-CN/security/strong-random.yaml new file mode 100644 index 0000000..2b87828 --- /dev/null +++ b/translations/content/zh-CN/security/strong-random.yaml @@ -0,0 +1,18 @@ +--- +title: 强随机数生成 +oldApproach: new SecureRandom() +modernApproach: getInstanceStrong() +summary: "获取平台最强的 SecureRandom 实现。" +explanation: "getInstanceStrong() 返回由 securerandom.strongAlgorithms 安全属性配置的最强 SecureRandom 实现。它自动选择平台的最佳安全算法。" +whyModernWins: +- icon: 🛡️ + title: 最强可用 + desc: "自动为平台选择最佳算法。" +- icon: 🔧 + title: 可配置 + desc: "通过安全属性在不同环境中自定义算法。" +- icon: 📖 + title: 意图清晰 + desc: "getInstanceStrong() 明确表明您需要最强的实现。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/security/tls-default.yaml b/translations/content/zh-CN/security/tls-default.yaml new file mode 100644 index 0000000..9eaccb2 --- /dev/null +++ b/translations/content/zh-CN/security/tls-default.yaml @@ -0,0 +1,18 @@ +--- +title: 默认 TLS 1.3 +oldApproach: 手动 TLS 配置 +modernApproach: TLS 1.3 默认 +summary: "TLS 1.3 默认启用——无需显式协议配置。" +explanation: "Java 11 添加了 TLS 1.3 支持并将其设为首选协议。SSLContext 自动协商 TLS 1.3(如果双方都支持),使现有代码更加安全,无需更改。" +whyModernWins: +- icon: 🛡️ + title: 更安全 + desc: "TLS 1.3 删除了过时的密码套件和握手模式。" +- icon: ⚡ + title: 更快握手 + desc: "TLS 1.3 将往返次数从 2 减少到 1。" +- icon: 🆓 + title: 无配置 + desc: "现有 HTTPS 代码自动受益。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/streams/collectors-flatmapping.yaml b/translations/content/zh-CN/streams/collectors-flatmapping.yaml new file mode 100644 index 0000000..61fd115 --- /dev/null +++ b/translations/content/zh-CN/streams/collectors-flatmapping.yaml @@ -0,0 +1,18 @@ +--- +title: Collectors.flatMapping() +oldApproach: 嵌套 flatMap +modernApproach: flatMapping() +summary: "使用 flatMapping() 在分组收集器内部进行扁平化。" +explanation: "Collectors.flatMapping() 在 groupingBy 等收集器内部将一对多映射作为下游收集器应用。这避免了 groupingBy 和 flatMap 的笨拙嵌套。" +whyModernWins: +- icon: 🧩 + title: 可组合 + desc: "作为 groupingBy 内的下游收集器使用。" +- icon: 📏 + title: 更扁平 + desc: "避免嵌套的 stream-inside-collector 模式。" +- icon: 📖 + title: 表达性强 + desc: "flatMapping 的意图一目了然。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/streams/optional-ifpresentorelse.yaml b/translations/content/zh-CN/streams/optional-ifpresentorelse.yaml new file mode 100644 index 0000000..5578072 --- /dev/null +++ b/translations/content/zh-CN/streams/optional-ifpresentorelse.yaml @@ -0,0 +1,18 @@ +--- +title: Optional.ifPresentOrElse() +oldApproach: Optional 上的 if/else +modernApproach: ifPresentOrElse() +summary: "在一次调用中处理 Optional 的存在和缺失两种情况。" +explanation: "ifPresentOrElse() 接受一个用于存在情况的 Consumer 和一个用于缺失情况的 Runnable。这消除了对 Optional 进行 if/else 的需要。" +whyModernWins: +- icon: 📏 + title: 单个表达式 + desc: "两种情况在一次方法调用中处理。" +- icon: 📖 + title: 声明式 + desc: "直接表达存在和缺失两种处理路径。" +- icon: 🚫 + title: 无 isPresent() 检查 + desc: "避免手动 isPresent() + get() 模式。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/streams/optional-or.yaml b/translations/content/zh-CN/streams/optional-or.yaml new file mode 100644 index 0000000..d46d3a6 --- /dev/null +++ b/translations/content/zh-CN/streams/optional-or.yaml @@ -0,0 +1,18 @@ +--- +title: Optional.or() 回退 +oldApproach: 嵌套回退 +modernApproach: .or() 链 +summary: "无需嵌套检查即可链式调用 Optional 回退。" +explanation: "Optional.or() 在有值时返回原始 Optional,否则返回由提供的 Supplier 生成的另一个 Optional。与 orElse() 不同,它保持 Optional 类型。" +whyModernWins: +- icon: 🔗 + title: 可链式调用 + desc: "在可读的管道中堆叠回退。" +- icon: 🎯 + title: 保持 Optional + desc: "返回 Optional 而非 T,因此可以继续链式调用。" +- icon: 📏 + title: 扁平 + desc: "无嵌套的 isPresent() 检查。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/streams/predicate-not.yaml b/translations/content/zh-CN/streams/predicate-not.yaml new file mode 100644 index 0000000..e7ca159 --- /dev/null +++ b/translations/content/zh-CN/streams/predicate-not.yaml @@ -0,0 +1,18 @@ +--- +title: 用 Predicate.not() 进行否定 +oldApproach: Lambda 否定 +modernApproach: Predicate.not() +summary: "使用 Predicate.not() 简洁地否定方法引用,而非编写 lambda 包装器。" +explanation: "Java 11 之前,否定方法引用需要将其包装在 lambda 中。Predicate.not() 允许直接否定方法引用,保持代码简洁。" +whyModernWins: +- icon: 👁 + title: 更简洁的否定 + desc: "无需仅为否定而将方法引用包装在 lambda 中。" +- icon: 📖 + title: 可读性强 + desc: "Predicate.not(String::isBlank) 清晰地表达意图。" +- icon: 🔗 + title: 可组合 + desc: "与其他 Predicate 方法如 and()、or() 配合使用。" +support: + description: 自 JDK 11 起可用(2018 年 9 月)。 diff --git a/translations/content/zh-CN/streams/stream-gatherers.yaml b/translations/content/zh-CN/streams/stream-gatherers.yaml new file mode 100644 index 0000000..0a20230 --- /dev/null +++ b/translations/content/zh-CN/streams/stream-gatherers.yaml @@ -0,0 +1,18 @@ +--- +title: 流 Gatherer +oldApproach: 自定义 Collector +modernApproach: gather() +summary: "使用 Gatherer 实现自定义中间流操作。" +explanation: "Gatherer 是一种新的中间流操作,可以表达内置操作(如 map 和 filter)无法表达的复杂转换。它们支持有状态处理和提前终止。" +whyModernWins: +- icon: 🧩 + title: 可组合 + desc: "Gatherer 与其他流操作组合使用。" +- icon: 🎯 + title: 有状态 + desc: "与 map/filter 不同,Gatherer 可以在元素之间维护状态。" +- icon: 🔀 + title: 灵活 + desc: "可以扩展、收缩或转换流,不受内置操作限制。" +support: + description: 在 JDK 24 中正式发布(JEP 485,2025 年 3 月)。 diff --git a/translations/content/zh-CN/streams/stream-iterate-predicate.yaml b/translations/content/zh-CN/streams/stream-iterate-predicate.yaml new file mode 100644 index 0000000..4f3e6b6 --- /dev/null +++ b/translations/content/zh-CN/streams/stream-iterate-predicate.yaml @@ -0,0 +1,18 @@ +--- +title: 带谓词的 Stream.iterate() +oldApproach: iterate + limit +modernApproach: iterate(seed, pred, op) +summary: "使用谓词停止迭代——流形式的 for 循环。" +explanation: "三参数 Stream.iterate(seed, hasNext, next) 像 for 循环一样工作:从种子值开始,在谓词成立时继续,并按步骤函数递进。" +whyModernWins: +- icon: 🎯 + title: 自然终止 + desc: "根据条件停止,而非任意 limit。" +- icon: 📖 + title: for 循环的流形式 + desc: "for(int i=0; i<10; i++) 对应的流形式。" +- icon: 🔗 + title: 可链式调用 + desc: "与 map、filter 等其他流操作链式调用。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/streams/stream-mapmulti.yaml b/translations/content/zh-CN/streams/stream-mapmulti.yaml new file mode 100644 index 0000000..494e67a --- /dev/null +++ b/translations/content/zh-CN/streams/stream-mapmulti.yaml @@ -0,0 +1,18 @@ +--- +title: Stream.mapMulti() +oldApproach: flatMap + List +modernApproach: mapMulti() +summary: "每个输入元素发出零个或多个元素,无需创建中间流。" +explanation: "mapMulti() 是 flatMap 的命令式替代方案,避免了为每个元素创建中间 Stream 或集合。使用 Consumer 按需发出元素。" +whyModernWins: +- icon: ⚡ + title: 更少分配 + desc: "每个元素不创建中间 Stream。" +- icon: 🎯 + title: 零或多个输出 + desc: "每个输入可以映射到任意数量的输出,包括零。" +- icon: 🔧 + title: 命令式控制 + desc: "比 flatMap 更精细地控制元素发出。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/streams/stream-of-nullable.yaml b/translations/content/zh-CN/streams/stream-of-nullable.yaml new file mode 100644 index 0000000..d7d6921 --- /dev/null +++ b/translations/content/zh-CN/streams/stream-of-nullable.yaml @@ -0,0 +1,18 @@ +--- +title: Stream.ofNullable() +oldApproach: Null 检查 +modernApproach: ofNullable() +summary: "从可空值创建零或一个元素的流。" +explanation: "Stream.ofNullable() 在值非 null 时返回单元素流,在 null 时返回空流。这是 flatMap 中处理可空映射的理想选择。" +whyModernWins: +- icon: 📏 + title: 简洁 + desc: "一次调用替代三元条件表达式。" +- icon: 🔗 + title: 可链式调用 + desc: "在 flatMap 中完美配合可空映射使用。" +- icon: 🚫 + title: 无 null 检查 + desc: "不需要显式 null 守卫。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/streams/stream-takewhile-dropwhile.yaml b/translations/content/zh-CN/streams/stream-takewhile-dropwhile.yaml new file mode 100644 index 0000000..bb807d8 --- /dev/null +++ b/translations/content/zh-CN/streams/stream-takewhile-dropwhile.yaml @@ -0,0 +1,18 @@ +--- +title: 流的 takeWhile / dropWhile +oldApproach: 手动循环 +modernApproach: takeWhile/dropWhile +summary: "根据谓词获取或丢弃流中的元素。" +explanation: "takeWhile() 在谓词为 true 时返回元素,在第一次失败时停止。dropWhile() 在谓词为 true 时跳过元素,然后返回其余所有元素。" +whyModernWins: +- icon: 🎯 + title: 短路 + desc: "一旦谓词失败立即停止处理。" +- icon: 📖 + title: 声明式 + desc: "清晰地表达获取/丢弃语义。" +- icon: 🔗 + title: 可链式调用 + desc: "与其他流操作无缝组合。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/streams/stream-tolist.yaml b/translations/content/zh-CN/streams/stream-tolist.yaml new file mode 100644 index 0000000..b2e5751 --- /dev/null +++ b/translations/content/zh-CN/streams/stream-tolist.yaml @@ -0,0 +1,18 @@ +--- +title: Stream.toList() +oldApproach: Collectors.toList() +modernApproach: .toList() +summary: "终端操作 toList() 替代冗长的 collect(Collectors.toList())。" +explanation: "Stream.toList() 返回不可修改的列表。它等效于 .collect(Collectors.toUnmodifiableList()) 但更简短。注意:结果是不可变的,与 Collectors.toList() 不同。" +whyModernWins: +- icon: 📏 + title: 7 个字符 vs 24 个 + desc: ".toList() 替代 .collect(Collectors.toList())。" +- icon: 🔒 + title: 不可变 + desc: "结果列表不可修改。" +- icon: 📖 + title: 流畅 + desc: "在管道末尾读起来自然。" +support: + description: 自 JDK 16 起广泛可用(2021 年 3 月) diff --git a/translations/content/zh-CN/streams/virtual-thread-executor.yaml b/translations/content/zh-CN/streams/virtual-thread-executor.yaml new file mode 100644 index 0000000..3e1eb32 --- /dev/null +++ b/translations/content/zh-CN/streams/virtual-thread-executor.yaml @@ -0,0 +1,18 @@ +--- +title: 虚拟线程执行器 +oldApproach: 固定线程池 +modernApproach: 虚拟线程执行器 +summary: "使用虚拟线程执行器实现无限轻量并发。" +explanation: "虚拟线程执行器为每个任务创建新的虚拟线程。无需调整池大小——JVM 根据需要管理虚拟线程,开销极低。" +whyModernWins: +- icon: ♾️ + title: 无需调整大小 + desc: "无需调整池大小——按需创建任意数量的线程。" +- icon: ⚡ + title: 轻量级 + desc: "每个虚拟线程的内存占用仅为千字节。" +- icon: 🔧 + title: 熟悉的 API + desc: "与现有 ExecutorService 代码无缝配合。" +support: + description: 自 JDK 21 LTS 起广泛可用(2023 年 9 月) diff --git a/translations/content/zh-CN/strings/string-chars-stream.yaml b/translations/content/zh-CN/strings/string-chars-stream.yaml new file mode 100644 index 0000000..43ffb1a --- /dev/null +++ b/translations/content/zh-CN/strings/string-chars-stream.yaml @@ -0,0 +1,18 @@ +--- +title: 字符串字符流 +oldApproach: 手动循环 +modernApproach: chars() 流 +summary: "将字符串字符作为流管道处理。" +explanation: "String.chars() 返回字符值的 IntStream,支持函数式字符处理。使用 (char) 转换或 Character 方法处理各个字符。" +whyModernWins: +- icon: 🔗 + title: 可链式调用 + desc: "对字符流使用 filter、map、collect。" +- icon: 📖 + title: 函数式风格 + desc: "声明式字符处理,无命令式循环。" +- icon: 🧩 + title: 可组合 + desc: "与其他流操作无缝组合。" +support: + description: 自 JDK 8+ 起可用(JDK 9+ 中有所改进) diff --git a/translations/content/zh-CN/strings/string-formatted.yaml b/translations/content/zh-CN/strings/string-formatted.yaml new file mode 100644 index 0000000..cd7921d --- /dev/null +++ b/translations/content/zh-CN/strings/string-formatted.yaml @@ -0,0 +1,18 @@ +--- +title: String.formatted() +oldApproach: String.format() +modernApproach: formatted() +summary: "直接在模板字符串上调用 formatted()。" +explanation: "String.formatted() 是等效于 String.format() 的实例方法,但在模板字符串上调用。这消除了将同一字符串传递两次的需要。" +whyModernWins: +- icon: 📖 + title: 读起来自然 + desc: "template.formatted(args) 比 String.format(template, args) 更流畅。" +- icon: 📏 + title: 更短 + desc: "无需重复字符串变量名。" +- icon: 🔗 + title: 可链式调用 + desc: "可与其他字符串方法链式调用。" +support: + description: 自 JDK 15 起广泛可用(2020 年 9 月) diff --git a/translations/content/zh-CN/strings/string-indent-transform.yaml b/translations/content/zh-CN/strings/string-indent-transform.yaml new file mode 100644 index 0000000..4f71739 --- /dev/null +++ b/translations/content/zh-CN/strings/string-indent-transform.yaml @@ -0,0 +1,18 @@ +--- +title: String.indent() 和 transform() +oldApproach: 手动缩进 +modernApproach: indent() / transform() +summary: "流畅地缩进文本并链式进行字符串转换。" +explanation: "indent(n) 为每行添加 n 个空格。transform(fn) 将任意函数应用于字符串,支持在字符串操作管道中链式调用任何转换。" +whyModernWins: +- icon: 📏 + title: 内置方法 + desc: "缩进是常见操作——现在只需一次调用。" +- icon: 🔗 + title: 可链式调用 + desc: "transform() 允许将自定义函数插入字符串管道。" +- icon: 🧹 + title: 更简洁 + desc: "无需 StringBuilder 循环进行缩进。" +support: + description: 自 JDK 12 起广泛可用(2019 年 3 月) diff --git a/translations/content/zh-CN/strings/string-isblank.yaml b/translations/content/zh-CN/strings/string-isblank.yaml new file mode 100644 index 0000000..a100a57 --- /dev/null +++ b/translations/content/zh-CN/strings/string-isblank.yaml @@ -0,0 +1,18 @@ +--- +title: String.isBlank() +oldApproach: trim().isEmpty() +modernApproach: isBlank() +summary: "用单个方法调用检查空白字符串。" +explanation: "isBlank() 在字符串为空或只包含空白字符时返回 true,使用与 strip() 相同的 Unicode 感知规则——而不像 trim() 那样仅限于 ASCII 空白。" +whyModernWins: +- icon: 📖 + title: 自我描述 + desc: "isBlank() 准确说明它检查的内容。" +- icon: 🌐 + title: Unicode 正确 + desc: "使用与 strip() 相同的 Unicode 空白定义。" +- icon: 📏 + title: 更少链式调用 + desc: "一个方法替代两个链式调用。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/strings/string-lines.yaml b/translations/content/zh-CN/strings/string-lines.yaml new file mode 100644 index 0000000..c9eb247 --- /dev/null +++ b/translations/content/zh-CN/strings/string-lines.yaml @@ -0,0 +1,18 @@ +--- +title: 用 String.lines() 分割行 +oldApproach: split("\\n") +modernApproach: lines() +summary: "使用 String.lines() 将文本分割为行流,无正则表达式开销。" +explanation: "String.lines() 返回按 \\n、\\r 或 \\r\\n 分割的行的 Stream。它是懒加载的,并正确处理所有行分隔符,无需正则表达式。" +whyModernWins: +- icon: ⚡ + title: 懒加载流 + desc: "行按需生成,不像 split() 那样一次全部生成。" +- icon: 🌐 + title: 正确的行分隔符 + desc: "处理 \\n、\\r\\n 和 \\r,无需正则表达式。" +- icon: 🔗 + title: 可链式调用 + desc: "直接链式调用 filter、map 和其他流操作。" +support: + description: 自 JDK 11 起可用(2018 年 9 月)。 diff --git a/translations/content/zh-CN/strings/string-repeat.yaml b/translations/content/zh-CN/strings/string-repeat.yaml new file mode 100644 index 0000000..760b8f5 --- /dev/null +++ b/translations/content/zh-CN/strings/string-repeat.yaml @@ -0,0 +1,18 @@ +--- +title: String.repeat() +oldApproach: StringBuilder 循环 +modernApproach: repeat() +summary: "无需循环即可重复字符串 n 次。" +explanation: "String.repeat(int) 返回字符串与自身拼接 n 次的结果。对于 0 返回空字符串,对于负数抛出 IllegalArgumentException。" +whyModernWins: +- icon: 📏 + title: 一行代码 + desc: "用一次调用替代 5 行 StringBuilder 代码。" +- icon: 📖 + title: 意图清晰 + desc: "\"=-\".repeat(20) 明确表达意图。" +- icon: 🚫 + title: 无循环 + desc: "无需手动维护计数器和 StringBuilder。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/strings/string-strip.yaml b/translations/content/zh-CN/strings/string-strip.yaml new file mode 100644 index 0000000..5871c9c --- /dev/null +++ b/translations/content/zh-CN/strings/string-strip.yaml @@ -0,0 +1,18 @@ +--- +title: String.strip() 与 trim() +oldApproach: trim() +modernApproach: strip() +summary: "使用 strip()、stripLeading()、stripTrailing() 进行 Unicode 感知的去空白处理。" +explanation: "trim() 只删除 ≤ U+0020 的字符(ASCII 控制字符和空格)。strip() 使用 Character.isWhitespace() 删除所有 Unicode 空白字符,包括不间断空格等。" +whyModernWins: +- icon: 🌐 + title: Unicode 正确 + desc: "处理来自每种文字的所有空白字符。" +- icon: 🎯 + title: 精确控制 + desc: "stripLeading() 和 stripTrailing() 提供单侧去除。" +- icon: 📖 + title: 语义更清晰 + desc: "strip() 的名称更准确地描述了现代空白处理。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/content/zh-CN/tooling/aot-class-preloading.yaml b/translations/content/zh-CN/tooling/aot-class-preloading.yaml new file mode 100644 index 0000000..22d5408 --- /dev/null +++ b/translations/content/zh-CN/tooling/aot-class-preloading.yaml @@ -0,0 +1,18 @@ +--- +title: AOT 类预加载 +oldApproach: 每次冷启动 +modernApproach: AOT 缓存 +summary: "缓存类加载和编译,实现即时启动。" +explanation: "AOT 类预加载从训练运行中缓存已加载和链接的类。后续运行直接从缓存加载,跳过类加载、验证和链接。" +whyModernWins: +- icon: ⚡ + title: 更快启动 + desc: "跳过类加载、验证和链接。" +- icon: 🔧 + title: 零代码更改 + desc: "无需修改应用程序代码。" +- icon: 📦 + title: 容器友好 + desc: "显著改善容器化 Java 应用的启动时间。" +support: + description: 在 JDK 25 LTS 中作为标准特性可用(JEP 514/515,2025 年 9 月) diff --git a/translations/content/zh-CN/tooling/built-in-http-server.yaml b/translations/content/zh-CN/tooling/built-in-http-server.yaml new file mode 100644 index 0000000..85ad6ff --- /dev/null +++ b/translations/content/zh-CN/tooling/built-in-http-server.yaml @@ -0,0 +1,18 @@ +--- +title: 内置 HTTP 服务器 +oldApproach: 外部服务器/框架 +modernApproach: jwebserver CLI +summary: "Java 18 内置了一个最小化 HTTP 服务器,用于原型开发和文件服务。" +explanation: "JDK 18 通过 jwebserver CLI 工具和 com.sun.net.httpserver 包添加了一个简单的、零依赖的 HTTP 文件服务器。" +whyModernWins: +- icon: 🚀 + title: 零设置 + desc: "在任意目录运行 jwebserver——无需安装、配置或依赖。" +- icon: 🎓 + title: 适合演示 + desc: "无需框架即可提供静态文件和演示原型。" +- icon: 🔧 + title: 可编程 + desc: "通过 Java API 可编程地嵌入最小化 HTTP 服务器。" +support: + description: 自 JDK 18 起可用(2022 年 3 月) diff --git a/translations/content/zh-CN/tooling/compact-object-headers.yaml b/translations/content/zh-CN/tooling/compact-object-headers.yaml new file mode 100644 index 0000000..b47841e --- /dev/null +++ b/translations/content/zh-CN/tooling/compact-object-headers.yaml @@ -0,0 +1,18 @@ +--- +title: 紧凑对象头 +oldApproach: 128 位头 +modernApproach: 64 位头 +summary: "将对象头大小减半,提高内存密度和缓存利用率。" +explanation: "紧凑对象头将每个对象的开销从 128 位(16 字节)减少到 64 位(8 字节)。这提高了内存密度,减少了 GC 压力,并提高了缓存局部性。" +whyModernWins: +- icon: 📦 + title: 头部缩小 50% + desc: "每个对象 8 字节而非 16 字节。" +- icon: ⚡ + title: 更好的缓存 + desc: "更小的对象意味着每个缓存行容纳更多对象。" +- icon: 🔧 + title: 零代码更改 + desc: "无需修改应用程序代码。" +support: + description: 在 JDK 25 LTS 中正式发布(JEP 519,2025 年 9 月)。 diff --git a/translations/content/zh-CN/tooling/jfr-profiling.yaml b/translations/content/zh-CN/tooling/jfr-profiling.yaml new file mode 100644 index 0000000..490e0fd --- /dev/null +++ b/translations/content/zh-CN/tooling/jfr-profiling.yaml @@ -0,0 +1,18 @@ +--- +title: 用 JFR 进行性能分析 +oldApproach: 外部分析器 +modernApproach: Java Flight Recorder +summary: "使用内置的 Flight Recorder 分析任何 Java 应用——无需外部工具。" +explanation: "Java Flight Recorder(JFR)是 JVM 内置的低开销分析工具。它记录 JVM、OS 和应用程序事件,可用于性能分析、诊断和监控。" +whyModernWins: +- icon: 🆓 + title: 内置 + desc: "无需安装或许可外部分析器。" +- icon: ⚡ + title: 低开销 + desc: "生产级分析,开销 < 1%。" +- icon: 📊 + title: 丰富数据 + desc: "CPU、内存、GC、线程、I/O 和自定义事件。" +support: + description: 自 JDK 9/11 起广泛可用(在 11 中开源) diff --git a/translations/content/zh-CN/tooling/jshell-prototyping.yaml b/translations/content/zh-CN/tooling/jshell-prototyping.yaml new file mode 100644 index 0000000..a4114f6 --- /dev/null +++ b/translations/content/zh-CN/tooling/jshell-prototyping.yaml @@ -0,0 +1,18 @@ +--- +title: 用 JShell 进行原型开发 +oldApproach: 创建文件 + 编译 + 运行 +modernApproach: jshell REPL +summary: "无需创建文件即可交互式尝试 Java 表达式。" +explanation: "JShell 是 Java 的读取-求值-打印循环(REPL)。无需完整的类定义即可测试表达式、实验 API 并探索库。" +whyModernWins: +- icon: ⚡ + title: 即时反馈 + desc: "输入表达式,立即看到结果。" +- icon: 🎓 + title: 适合学习 + desc: "非常适合探索 API 和学习 Java 特性。" +- icon: 🔧 + title: 无文件 + desc: "无需创建类或文件即可测试代码片段。" +support: + description: 自 JDK 9 起广泛可用(2017 年 9 月) diff --git a/translations/content/zh-CN/tooling/junit6-with-jspecify.yaml b/translations/content/zh-CN/tooling/junit6-with-jspecify.yaml new file mode 100644 index 0000000..20192b5 --- /dev/null +++ b/translations/content/zh-CN/tooling/junit6-with-jspecify.yaml @@ -0,0 +1,18 @@ +--- +title: 使用 JSpecify null 安全的 JUnit 6 +oldApproach: 未注解的 API +modernApproach: '@NullMarked API' +summary: "JUnit 6 采用 JSpecify @NullMarked,使 null 契约在整个测试 API 中显式化。" +explanation: "JUnit 5 发布时没有标准化的可空性注解,让工具和开发者不得不猜测 null 行为。JUnit 6 使用 JSpecify 的 @NullMarked 将非 null 作为默认值。" +whyModernWins: +- icon: 📜 + title: 显式契约 + desc: "@NullMarked 在 JUnit 6 模块上直接记录 null 语义。" +- icon: 🔒 + title: 工具支持 + desc: "IDE 和分析器可以在测试代码中标记 null 违规。" +- icon: 🧹 + title: 更少 @Nullable + desc: "非 null 是默认值——只有异常需要注解。" +support: + description: 自 JUnit 6.0 起可用(2025 年 10 月,需要 Java 17+) diff --git a/translations/content/zh-CN/tooling/multi-file-source.yaml b/translations/content/zh-CN/tooling/multi-file-source.yaml new file mode 100644 index 0000000..db4a989 --- /dev/null +++ b/translations/content/zh-CN/tooling/multi-file-source.yaml @@ -0,0 +1,18 @@ +--- +title: 多文件源代码启动器 +oldApproach: 先编译所有文件 +modernApproach: 源代码启动器 +summary: "无需显式编译步骤即可启动多文件程序。" +explanation: "Java 22+ 在启动入口文件时可以自动编译引用的源文件。这对小型多文件程序消除了显式的 javac 步骤。" +whyModernWins: +- icon: 🚀 + title: 零设置 + desc: "小型多文件程序无需构建工具。" +- icon: ⚡ + title: 一个命令 + desc: "java Main.java——其余依赖自动编译。" +- icon: 🎓 + title: 适合学习 + desc: "非常适合教学示例和小型实用程序。" +support: + description: 自 JDK 22 起可用(2024 年 3 月) diff --git a/translations/content/zh-CN/tooling/single-file-execution.yaml b/translations/content/zh-CN/tooling/single-file-execution.yaml new file mode 100644 index 0000000..c89e77d --- /dev/null +++ b/translations/content/zh-CN/tooling/single-file-execution.yaml @@ -0,0 +1,18 @@ +--- +title: 单文件执行 +oldApproach: 两步编译 +modernApproach: 直接启动 +summary: "无需 javac 直接运行单文件 Java 程序。" +explanation: "Java 启动器可以在一个命令中编译并运行单个源文件。非常适合脚本、工具和探索,无需构建步骤。" +whyModernWins: +- icon: ⚡ + title: 一个命令 + desc: "java File.java 在一步中编译并运行。" +- icon: 🚀 + title: 无需构建工具 + desc: "非常适合脚本、工具和快速实验。" +- icon: 🎓 + title: 对初学者友好 + desc: "新开发者无需学习构建系统即可运行 Java。" +support: + description: 自 JDK 11 起广泛可用(2018 年 9 月) diff --git a/translations/strings/zh-CN.yaml b/translations/strings/zh-CN.yaml new file mode 100644 index 0000000..a81ced1 --- /dev/null +++ b/translations/strings/zh-CN.yaml @@ -0,0 +1,81 @@ +site: + title: java.evolved + tagline: Java 已进化。您的代码也可以。 + tagline_line1: Java 已进化。 + tagline_line2: 您的代码也可以。 + description: 现代 Java 代码片段集合。每个旧 Java 模式与其简洁的现代替代方案并排展示。 + heroSnippetCount: ✦ {{snippetCount}} 个现代模式 · Java 8 → Java 25 + heroOld: 旧版 + heroModern: 现代 + allComparisons: 所有对比 + snippetsBadge: '{{snippetCount}} 个代码片段' +nav: + allPatterns: ← 所有模式 + toggleTheme: 切换主题 + viewOnGitHub: 在 GitHub 上查看 + selectLanguage: 选择语言 +breadcrumb: + home: 首页 +sections: + codeComparison: 代码对比 + whyModernWins: 为什么现代方式更好 + oldApproach: 旧方式 + modernApproach: 现代方式 + sinceJdk: 自 JDK + difficulty: 难度 + jdkSupport: JDK 支持 + howItWorks: 工作原理 + relatedDocs: 相关文档 + relatedPatterns: 相关模式 +filters: + show: '显示:' + all: 全部 +difficulty: + beginner: 入门 + intermediate: 中级 + advanced: 高级 +search: + placeholder: 搜索代码片段… + noResults: 未找到结果。 + esc: ESC + searchTrigger: 搜索… + navigate: 导航 + open: 打开 + close: 关闭 +cards: + old: 旧版 + modern: 现代 + hoverHint: 悬停查看现代版 → + hoverHintRelated: 悬停查看现代版 ➜ + touchHint: 👆 点击或滑动 → +copy: + copy: 复制 + copied: 已复制! +share: + label: 分享 +view: + expandAll: 展开全部 + collapseAll: 收起全部 +stats: + modernPatterns: 现代模式 + jdkVersions: 覆盖的 JDK 版本 + categories: 分类 + linesOfPython: 所需 Python 代码行数 +footer: + tagline: Java 已进化。您的代码也可以。 + madeWith: 用 ❤️ 制作,作者 + and: 和 + inspiredBy: 灵感来自 + viewOnGitHub: 在 GitHub 上查看 +copilot: + headline: 使用 GitHub Copilot 现代化您的 Java 代码库。 + description: 让 Copilot 帮您自动将遗留模式迁移到现代 Java。 + appModernization: 应用现代化 → + javaGuide: Java 指南 → +support: + available: 可用 + preview: 预览 + experimental: 实验性 +untranslated: + notice: 此页面尚未翻译为{{localeName}}。 + viewInEnglish: 查看英文版