Fwd: Single Abstract Method for SAMs cannot be polymorphic

Grégoire Neuville gregoire.neuville at gmail.com
Wed Apr 3 03:58:04 PDT 2013


> A generic SAM is not a valid target type for a lambda, but it may be one
> for a method reference.
>

 Ok, understood.


> You *can* have generic (polymorphic) SAMs.  You just cannot initialize
> them with lambdas.  Use method refs instead.
>

Yup, got it, read you loud and clear :-) Thanks !


> (BTW, lambda support in IntelliJ is very impressive but still new, so
> there are bound to be differences between what IntelliJ accepts and what
> javac does.)


Yeah, I noticed that, indeed. It's especially evident as far as type
inference is concerned : most of the times javac is smarter in the matter,
but sometimes - quite rarely actually - IntelliJ prevails.


>
> On 4/2/2013 4:16 PM, Grégoire Neuville wrote:
>
>> I meant 'the annotation *in itself* is marked as erroneous' : so does the
>> code '(a, g) -> new Gen<>()'.
>>
>> Note though that the sole annotation (i.e if 'CoArbitrary<?> coArb = (a,
>> g)
>> -> new Gen<>();' is commented) doesn't prevent the code from being
>> compiled
>> by javac : should it ?
>>
>>
>> On 2 April 2013 22:04, Grégoire Neuville <gregoire.neuville at gmail.com>**
>> 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
>>>
>>>
>>
>>
>>


-- 
Grégoire Neuville



-- 
Grégoire Neuville


More information about the lambda-dev mailing list