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:
JavaConstant.MethodHandle
indicates that it is not really used outside of ByteBuddy's AgentBuilder.LambdaInstrumentationStrategy.LambdaInstanceFactory.LambdaMethodImplementation
class. Is it a viable structure for representing a MethodHandle
in the constant pool for modern JVMs?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.