compiler accepts incompatible method reference for Sam conversion

Rémi Forax forax at univ-mlv.fr
Wed Jul 13 01:06:44 PDT 2011


On 07/13/2011 06:01 AM, Ali Ebrahimi wrote:

Hi Ali,

...
> MethodHandle mh = MethodHandles.lookup().findStatic(MethodHandleTest.class,
> "sTest", MethodType.methodType(void.class,int.class,int.class));
> MethodHandle smh = mh.asSpreader(Object[].class,
> mh.type().parameterCount());
>
> smh.invoke(new Object[]{i,i});<===============crash
>
> main cause: mh.asSpreader
>
> I don't known this crash appears in jdkb147.

What you want here is to use asCollector, not asSpreader.
asSpreader requires that the method as already an object array
and extract the value from it.

In your example, the call to mh.asSpreader should return a runtime 
exception,
I will investigate why it's not the case when I will be at my office :)

> Best Regards,
> Ali Ebrahimi

regards,
Rémi




More information about the lambda-dev mailing list