SAM conversion of inlined lambda expression

Thomas Jung thomas.andreas.jung at googlemail.com
Sat Aug 7 07:57:13 PDT 2010


Hi Rémi,

you're right. Defining

public static <A,B,C> Function<A,C> simpleCompose(Function<B,C> g,
Function<A, B> f){
    return Functions.compose(g,f);
}
Function<String, String> c = simpleCompose(#(x){ "a" + x }, #(x){ x + "b" });

works. Is there is way to get some debugging information of the type inferencer?

Thomas

On 7 August 2010 15:16, Rémi Forax <forax at univ-mlv.fr> wrote:
>  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