diff --git a/rules/S7465/java/rule.adoc b/rules/S7465/java/rule.adoc index 58027017b3..2bf08debfe 100644 --- a/rules/S7465/java/rule.adoc +++ b/rules/S7465/java/rule.adoc @@ -1,8 +1,15 @@ == Why is this an issue? -Library authors often design APIs to be versatile, enabling them to handle diverse scenarios. Consequently, when we provide a lambda expression as an argument to a library function, we may find ourselves with unused arguments. Naming these arguments can contribute to unnecessary code expansion and diminish readability. Furthermore, it obscures the crucial fact that the argument is intentionally unused. To resolve this and clearly indicate the intent, unused arguments should be denoted with an underscore `_`, a feature introduced in Java 22. +Library authors often design versatile APIs to handle diverse scenarios. +When such an API takes a function as an argument, we may find ourselves +writing a lambda expression where some arguments are unused. +Naming these arguments can lead to unnecessary verbosity. +Java 22 introduces the unnamed variable pattern `_` that clearly indicates +the intent not to use the variable. == How to fix it +In order to clearly indicate the intent, unused arguments should be denoted +with an unnamed variable pattern `_`. === Code examples