Fwd: Single Abstract Method for SAMs cannot be polymorphic

Grégoire Neuville gregoire.neuville at gmail.com
Wed Apr 3 05:47:32 PDT 2013


Ok, thanks for the answers !


On 3 April 2013 14:11, Brian Goetz <brian.goetz at oracle.com> wrote:

> Depends what you mean by "temporary".  It was a deliberate choice to leave
> things this way, so, while we might change our mind in a few years and add
> a syntax for generic lambdas, this is the way it will be for Java 8.
>
>
> On 4/3/2013 6:57 AM, Grégoire Neuville wrote:
>
>> Thanks for the clarification. Is it a temporary or permanent limitation ?
>>
>>
>> On 2 April 2013 22:23, Brian Goetz <brian.goetz at oracle.com> wrote:
>>
>>  Not actually true.  SAM methods can be generic.  However, the only way to
>>> assign to such a SAM is with a method reference to a generic method.
>>>   There's no syntax for *lambdas* that allows you to specify the type
>>> params.
>>>
>>> You should be able to use Gen::new in your example (though not sure if
>>> the
>>> wildcards are going to mess it up.)
>>>
>>>
>>>
>>> On 4/2/2013 4:04 PM, Grégoire Neuville wrote:
>>>
>>>  Hi all,
>>>>
>>>> The below code :
>>>>
>>>> public class TestGenericSAM {
>>>>
>>>>     class Gen<B> {}
>>>>
>>>>     @FunctionalInterface
>>>>     interface CoArbitrary<A> {
>>>>       abstract <B> Gen<B> coarbitrary(A a, Gen<B> g);
>>>>     }
>>>>
>>>>     void test() {
>>>>       CoArbitrary<?> coArb = (a, g) -> new Gen<>();
>>>>     }
>>>> }
>>>>
>>>> doesn't compile. I guess this is by design (the annotation alone is
>>>> marked
>>>> as erroneous by IntelliJ), but I'm just wondering why.
>>>>
>>>> Thanks a lot for any explanation !
>>>>
>>>>
>>>>
>>
>>


-- 
Grégoire Neuville


More information about the lambda-dev mailing list