[Java] (JDK24 in my case) use of underscore variable triggers checkstyle LambdaParameterName
Hello team,
I am using JDK 24, and since a couple of last Java versions, we can use the underscore sign to substitute a variable that will not be used, what Java called an unnamed variable.
https://medium.com/@benweidig/looking-at-java-22-unnamed-variables-patterns-f9de0b1e2750
For instance:
final boolean someboolean = Optional.ofNullable(getMap()).map(_ -> getHeaders()) [...]
While this is perfectly fine and compiles, checkstyle will flag:
LambdaParameterName
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<outputDirectory>target/reports/checkstyle</outputDirectory>
<configLocation>google_checks.xml</configLocation>
<outputFileFormat>xml</outputFileFormat>
</configuration>
</plugin>
Could you please help take into account the new java underscore unnamed variable?
Thank you very much and good day.
Hey Google, same issue there. Could you help?
Issue should be reported without any reference to checkstyle. @patpatpat123 , @ryleighmikami , please report it properly
We are planning to update the style guide to allow this, the intent is not to discourage unnamed variables or patterns.
We can certainly update the style guide to make this clearer, but I don't think anything in it right now precludes the use of unnamed variables or patterns. Technically, _ is not an identifier so it is not covered by the rules about identifier naming. We don't currently have anything at all to say about patterns, unnamed or otherwise.