In code 2, I get your error in Eclipse, which is not helpful. When compiling on the command line, I get this error:
J.java:28: error: illegal initializer for Function<T,R>
Function<T, R> o = {x -> {
^
where T,R are type-variables:
T extends Object declared in method <T,R>m2(Function<T,R>)
R extends Object declared in method <T,R>m2(Function<T,R>)
J.java:28: error: lambda expression not expected here
Function<T, R> o = {x -> {
^
2 errors
Your braces are unnecessary. The outer pair of braces is attempting to create an array initializer, not a lambda expression. The inner braces does attempt to create a lambda expression, but that can't be done within an array initializer.
You can have an expression be the return type of a lambda expression, without any braces. Try:
Function<T, R> o = x -> f.apply(x);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…