findVirtual problem

Christian Thalinger Christian.Thalinger at Sun.COM
Wed Aug 19 01:28:32 PDT 2009


John Rose wrote:
> On Aug 18, 2009, at 6:07 AM, Raffaello Giulietti wrote:
> 
>> Hi Christian,
>>
>> do an upcast
>>
>> String result = mh.<String>invoke((Object) "foo");
> 
> Yes.  The difference between the two call sites is:
>    (Ljava/lang/String;)Ljava/lang/String;
> vs.
>    (Ljava/lang/Object;)Ljava/lang/String;
> 
> The actual (erased) types of the arguments determine the descriptor,  
> and hence the required MethodType.
> 
> To avoid all such issues, with a possible performance hit, use the  
> more lenient calling sequence supplied (as a non-primitive) by  
> MethodHandles.invoke:
>    String result = (String) MethodHandles.invoke(mh, "foo");
> 
> MHs.invoke (which has fixed-arity and varargs versions) supplies all- 
> you-can-eat boxing and casting.
> 
> This is an issue being discussed by the EG, whether the lenient  
> semantics of MHs.invoke should be supported at all times by the  
> primitive MH.invoke.  The cost of doing so would be increased  
> complexity at every MH invocation site, in many JVMs.  The benefit  
> would be ease of programming.

I see.  Thank you for the explanation.

-- Christian


More information about the mlvm-dev mailing list