This was received from the suggestion box …
My thoughts on this: local functions are a potentially useful feature, and one that interacts nicely with the concise form, but the two features are orthogonal; there’s nothing to be gained by doing them together that is not gained by doing them sequentially in either order. While I’ve got nothing against local functions, I would rather do local functions in the context of a more general cleanup about nesting constraints (e.g., restrictions on static fields of inner classes, private classes nested in interfaces, local interfaces and enums, etc.) There’s a whole pile of “it makes sense to nest X in Y, but you can’t” irregularities that can be cleaned up at once — but I think there’s more immediate payback in doing the more constrained feature of concise method bodies first. > Begin forwarded message: > > From: Lukas Eder <lukas.e...@gmail.com> > Subject: JEP draft: Concise Method Bodies - extend this to local functions? > Date: September 19, 2018 at 4:44:04 PM EDT > To: amber-spec-comme...@openjdk.java.net > > Hello, > > I've just seen this new JEP draft, which really looks very useful: > http://openjdk.java.net/jeps/8209434 > > Now, given that this would be possible: > > int x(String s) -> s.length(); > > And given that this almost looks like a named lambda expression, could this > maybe be an occasion to re-discuss the possibility of supporting named > lambda expression / local functions? > > E.g. > > void m() { > > // lambda local to m() > ToIntFunction<String> x1 = (String s) -> s.length(); > > // "method" local to m() > int x2(String s) -> s.length(); > > // We can now do: > int i1 = x1.apply("abc"); > > // More concise > int i2 = x2("abc"); > } > > I know this was discussed for Java 8 and rejected, but given the high > similarity of the currently proposed concise method body syntax and the > lambda syntax, I feel that on a high level, this might appear coherent and > useful. > > Of course, in such a case, it would appear useful to allow the original > method body syntax as well in a local method: > > void m() { > int x3(String s) { > return s.length(); > } > } > > Also, many other languages have this feature, e.g. Scala, Ceylon, Kotlin > > Thanks, > Lukas