Lets say I'm writing a deserialization utility, and would like to have performance better than Reflection.
I have a Map<Class, MethodHandle>
, where the MethodHandle is the desired constructor for the given Class. When a user calls T deserialize(ByteBuffer, Class<T>)
, it gets the respective MethodHandle from the Map, gets the constructor arguments from the buffer, and then calls MethodHandle::invoke
. And this works fine.
The thing is, unless a MethodHandle is static final
, then performance is equivalent to reflection.
Is there a way to use LambdaMetaFactory, or MutableCallSite to improve performance? I don't see how LambdaMetaFactory can be used (we need to know the interface type ahead of time?), and creating a MutableCallSite would still not be static final
.