SAM conversion of inlined lambda expression

Rémi Forax forax at univ-mlv.fr
Sat Aug 7 06:16:58 PDT 2010


  Le 07/08/2010 09:58, Thomas Jung a écrit :
> 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
>    

This is a bug, the prototype have a problem to infer types
if there is a wilcard in the middle.

by example, this doesn't compile:
Function<String, ? extends String> b = #(x){ x + "b" };

So you can't use compose which is declared:|*
*| <A,B,C> 
<../../../../com/google/common/base/Functions.html#compose%28com.google.common.base.Function,%20com.google.common.base.Function%29>Function 
<../../../../com/google/common/base/Function.html><A,C> |compose 
<../../../../com/google/common/base/Functions.html#compose%28com.google.common.base.Function,%20com.google.common.base.Function%29>(Function 
<../../../../com/google/common/base/Function.html><B,C> g, Function 
<../../../../com/google/common/base/Function.html><A,*? extends* B> f)|

Rémi




More information about the lambda-dev mailing list