Identify and apply modern Java (Java 8+) refactoring opportunities to improve readability, maintainability, and performance.
Prerequisites: Run ./mvnw compile or mvn compile before applying any changes. If compilation fails, stop immediately — do not proceed until the project compiles successfully.
Core areas: Lambda expressions and method references (over anonymous classes), Stream API for declarative collection processing, Optional for null-safe APIs, java.time API (replacing Date/Calendar), default interface methods, var type inference, unmodifiable collection factory methods (List.of(), Set.of(), Map.of()), CompletableFuture for composable async programming, text blocks for multi-line strings, Java 25 Fl...
当您需要重构 Java 代码以采用现代 Java 功能 (Java 8+) 时使用 - 包括将匿名类迁移到 lambda、用 Stream API 替换 Iterator 循环、采用Optional 实现 null 安全、从旧版 Date/Calendar 切换到 java.time、使用集合工厂方法、迁移到 CompletableFuture 进行异步操作、应用文本块、var 推断或利用灵活的构造函数体和模块导入声明等 Java 25 功能。 java 技能项目的一部分 来源:jabrena/cursor-rules-java。