SAM conversion of inlined lambda expression

Thomas Jung thomas.andreas.jung at googlemail.com
Sat Aug 7 00:58:52 PDT 2010


Hi,

I'm playing a bit with the prototype (i.e. I've not read the specs in
full) and I'm puzzled after my second step.

The initial code that uses Function
(http://guava-libraries.googlecode.com/svn/trunk/javadoc/com/google/common/base/Function.html)
is:

Function<String, String> a = #(x){ "a" + x };
Function<String, String> b = #(x){ x + "b" };
assertEquals("axb", Functions.compose(a, b).apply("x"));

This works with type inference and does the conversion to the type
Function<F,T>. But if I inline the lambda expression it won't convert
them.

Function<String, String> c = Functions.<String, String>
compose(#(String x){ "a" + x }, #(String x){ x + "b" });

I've added all type annotations to rule out that this is the problem.
The error message is:
"method compose in class Functions cannot be applied to given types".
(Can I get more information here about the types/problem?)

Is this not supported?

Thomas


More information about the lambda-dev mailing list