Lambda and JSR 292 method handle

Neal Gafter neal at gafter.com
Fri Dec 18 07:28:58 PST 2009


On Fri, Dec 18, 2009 at 6:48 AM, Rémi Forax <forax at univ-mlv.fr> wrote:

> Le 18/12/2009 15:41, Neal Gafter a écrit :
>
> Do the types representing jsr292's JavaMethodHandle obey subtype
>> relationships that make them covariant on return type and contravariant on
>> argument types?
>>
>
> Yes, if they are invoked using invokeLambda() and no other invoke*.
> For the record, even if this could changed, there are two other method
> invoke*,
> invokeExact that requires the exaxct same signature and invokeGeneric that
> is able
> to do conversion like boxing/unboxing etc.
>

This doesn't answer my question.  I'm taking about subtyping among values of
function type, not about the invocation point.  Specifically, it should be
the case that, given

*#Object(String) f1;*
*#String(Object) f2 = ...;*

you can assign

*f1 = f2;*

This needs to be a subtype conversion (e.g. no code should have to be
generated for this conversion to occur) for reasons that I can explain if it
is not already clear.  The ParallelArray APIs take advantage of this kind of
subtyping by defining its function types using interfaces and wildcards.  If
that API is recast using function types, some flexibility will be lost
unless function types act this way too.

The answer may depend on *how* function types are mapped to
JavaMethodHandle.  There is no public proposal on the table yet for how that
would work.  I hope the anonymous experts inside Sun that Mark suggested are
devoted to this work are on it.

Cheers,
Neal


More information about the lambda-dev mailing list