The example shown in the description of the MethodHandle
class throws a WrongMethodTypeException
in the invocation of the statement mh.invokeExact("daddy",'d','n')
with the following description: (CC)Ljava/lang/String; cannot be called with a different arity as ([Ljava/lang/Object;)Ljava/lang/Object;
.
The MethodHandle
object mh
has a symbolic type descriptor corresponding to: (CC)Ljava/lang/String
. But when we are invoking mh.invokeExact("daddy",'d','n')
, the arguments: d
and n
are passed as an Object
array and then they are not matching with the arguments of the type char
.
I know that I can resolve the above problem using the invokeWithArguments
instead of the invokeExcat
or the invoke
, but this example was supposed to work as presented in the description of the MethodHandle
of Java 7 API. Besides that, the invokeWithArguments
has a performance overhead in relation to invoke
/invokeExact
.
How are you compiling this?
It sounds suspiciously like a known Eclipse bug to me.
I've just checked with javac and this code:
seems to work OK:
The relevant portion of output from javap seems sane as well: