Description

For formal parameters of implicitly typed lambda expressions, allow the reserved type name var to be used, so that:

(var x, var y) -> x.process(y)

is equivalent to:

(x, y) -> x.process(y)

An implicitly typed lambda expression must use var for all its formal parameters or for none of them. In addition, var is permitted only for the formal parameters of implicitly typed lambda expressions --- explicitly typed lambda expressions continue to specify manifest types for all their formal parameters, so it is not permitted for some formal parameters to have manifest types while others use var. The following examples are illegal:

In theory, it would be possible to have a lambda expression like the last line above, which is semi-explicitly typed (or semi-implicitly typed, depending on your point of view). However, it is outside the scope of this JEP because it deeply affects type inference and overload resolution. This is the main reason for keeping the restriction that a lambda expression must specify all manifest parameter types or none. We also want to enforce that the type inferred for a parameter of an implicitly typed lambda expression is the same whether var is used or not. We may return to the problem of partial inference in a future JEP. Also, we do not wish to compromise the brevity of the shorthand syntax, so we won't allow expressions like:

var x -> x.foo()

Alternatives

Risks and Assumptions

This JEP has no risk of source incompatibility when var is added before a parameter name in an implicitly typed lambda expression, because the type inferred for the parameter without var is the same as the type inferred with var.