# Can lambda parameter types be left off if potentially inferable from context? [duplicate]

This Java answer (and this one) uses a lambda that does not explicitly declare its parameter type, but this Scala answer includes a parameter type. in both cases, the type could be inferred when it is assigned to a variable. For example, for a lambda that takes an int and returns an int:

Function<Integer, Integer> f = a->... // Java

val f: Int => Int = a=>... // Scala


My question is: should the type parameters be included in the lambda, or can we assume that they are declared as above?

• Is there any problem with being able to handle more input types than mandated by the spec? – John Dvorak Mar 21 '17 at 15:29
• @JanDvorak what do you mean? – Brian McCutchon Mar 21 '17 at 15:46
• @Poke I think that answers it. – Brian McCutchon Mar 21 '17 at 15:50