The journey of getting there

Using an underscore to mark unused parameters required changes in the Java language.

Until Java 8, the underscore was used as a valid identifier. The first step was to deny permission to use an underscore as a regular identifier. So, Java 8 issued a compiler warning for the usage of _ as the name of formal parameters in lambdas. This was simple, and had no backward-compatibility issues since lambdas were introduced in Java 8. Moving forward, Java 9 replaced the compiler warning message with compilation errors for using underscores as parameter names.

With JEP 302, developers can use _ to mark an unused method parameter for the following:

  • Lambdas
  • Methods
  • Catch handlers

In the next section, you'll see how (in the future) your lambda parameters will be able to shadow the variables with the same name in their enclosing scopes.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.76.72