Search code examples
byte-buddy

If I have a JavaConstant.MethodHandle and I want to somehow pass it to MethodCall.invoke() is there a way to do it?


Suppose I am generating a class using ByteBuddy.

Suppose further I have a JavaConstant.MethodHandle that I have somehow made.

Suppose now I want to use that JavaConstant.MethodHandle as a notional argument to MethodCall.invoke() as part of my class generation. Clearly at the moment I cannot do this, since MethodCall.invoke takes, at best, a MethodDescription. But the gist is: (a) I have found this MethodHandle, (b) MethodHandle instances can be stored in the constant pool, so {waves hands furiously} (c) ByteBuddy does magic and I can implement a generated method by saying MethodCall.invoke(myMethodHandleConstantGoesHere).

So: is it reasonable (or is it nonsensical) to talk about an enhancement to MethodCall.invoke() such that it could take a JavaConstant.MethodHandle and do the magic to resolve it from the constant pool?

A couple of other interesting bits of background information:


Solution

  • This was not possible but after your PR it will be in the next release. It will be possible from Byte Buddy 1.10.18.