Local variable syntax for Lambda parameters

As discussed earlier in this chapter, the var identifier was introduced in Java 10. With the latest version, Java 11, var can be used in implicitly typed Lambda expressions. The following is an example of two equivalent Java statements:

  • (object1, object2) -> object1.myMyethod(object2)
  • (var object1, var object2) -> object1.myMethod(object2)

In the first statement, the var identifier is not used. In the second statement, var is used. It is important to note that if var is used in an implicitly typed Lambda expression, it must be used for all formal parameters.

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

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