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 建構程式設計程式設計功能。 java 技能專案的一部分 來源:jabrena/cursor-rules-java。