141-java-refactoring-with-modern-features
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseModern Java Development Guidelines (Java 8+)
现代Java开发指南(Java 8+)
Identify and apply modern Java (Java 8+) refactoring opportunities to improve readability, maintainability, and performance.
What is covered in this Skill?
- Lambda expressions and method references (over anonymous classes)
- Stream API for declarative collection processing
- for null-safe APIs
Optional - API (replacing
java.time/Date)Calendar - Default interface methods, type inference
var - Unmodifiable collection factory methods (,
List.of(),Set.of())Map.of() - Text blocks for multi-line strings
- Java 25 Flexible Constructor Bodies (JEP 513)
- Java 25 Module Import Declarations (JEP 511)
Scope: The reference is organized by examples (good/bad code patterns) for each core area. Apply recommendations based on applicable examples.
识别并应用现代Java(Java 8+)重构机会,以提升代码的可读性、可维护性和性能。
本Skill涵盖哪些内容?
- Lambda表达式和方法引用(替代匿名类)
- 用于声明式集合处理的Stream API
- 用于空值安全API的
Optional - API(替代
java.time/Date)Calendar - 默认接口方法、类型推断
var - 不可修改集合工厂方法(、
List.of()、Set.of())Map.of() - 用于多行字符串的文本块
- Java 25灵活构造函数体(JEP 513)
- Java 25模块导入声明(JEP 511)
适用范围: 本参考文档按每个核心领域的示例(好/坏代码模式)组织。请根据适用的示例应用建议。
Constraints
约束条件
Before applying any modern Java refactoring, ensure the project compiles. If compilation fails, stop immediately — do not proceed until the project compiles successfully. After applying improvements, run full verification.
- MANDATORY: Run or
./mvnw compilebefore applying any changesmvn compile - SAFETY: If compilation fails, stop immediately — do not proceed until the project compiles successfully
- VERIFY: Run or
./mvnw clean verifyafter applying improvementsmvn clean verify - BEFORE APPLYING: Read the reference for detailed good/bad examples, constraints, and safeguards for each modern Java feature
在应用任何现代Java重构之前,确保项目可以编译。如果编译失败,请立即停止——在项目成功编译前不要继续。应用改进后,运行完整验证。
- 强制要求:在应用任何更改前运行或
./mvnw compilemvn compile - 安全提示:如果编译失败,请立即停止——在项目成功编译前不要继续
- 验证:应用改进后运行或
./mvnw clean verifymvn clean verify - 应用前准备:阅读参考文档,了解每个现代Java特性的详细好/坏示例、约束条件和防护措施
When to use this skill
何时使用本Skill
- Review Java code for modern Java development
- Apply best practices for modern Java development in Java code
- 审查Java代码以进行现代Java开发
- 在Java代码中应用现代Java开发的最佳实践
Reference
参考资料
For detailed guidance, examples, and constraints, see references/141-java-refactoring-with-modern-features.md.
如需详细指南、示例和约束条件,请参阅references/141-java-refactoring-with-modern-features.md。