Identify and apply functional programming principles in Java to improve immutability, expressiveness, and maintainability.
Prerequisites: Run ./mvnw compile or mvn compile before applying any changes. If compilation fails, stop immediately — do not proceed until the project compiles successfully. Also verify that the project's maven-compiler-plugin source/target supports the Java features being used.
Core areas: Immutable objects and Records (JEP 395), pure functions free of side effects, functional interfaces (Function, Predicate, Consumer, Supplier) and custom @FunctionalInterface types, lambda expressions and method references, Stream API (filter/map/reduce pipelines, parallel streams, toUnmodifiable collectors), Optional idiomatic usage (map/flatMap/filter/orElse over isPresent()+get()), function compositi...
當您需要在 Java 中應用函數式程式設計原理時使用 - 包括編寫不可變物件和記錄、純函數、函數式介面、lambda 表達式、流 API 管道、空安全性的可選、函數組合、高階函數、instanceof 和 switch 的模式匹配、用於受控層次結構的密封類別/介面、用於自訂操作的應用程式收集器、柯里化/部分應用程式的應用程式/部分應用程式收集器。 java 技能專案的一部分 來源:jabrena/cursor-rules-java。