In short: 1. I have some final class that I want to create dynamic proxy for it. How can I do it? 2. Can I convert MethodHandle to Method?
Details First of all, does exists any API to convert MethodHandle to Method? Something like in java.lang.invoke.MethodHandles
public MethodHandle unreflect(Method m) throws IllegalAccessException;
but the opposite way arrond?
Let say I want to create dynamic java.lang.reflect.Method. It is defiend as
public final
class Method extends AccessibleObject implements GenericDeclaration,
Member ;
So, if I want to use JDK Dynamic proxy I must use some interface (Member for example). There 2 main drawabacks though. First, method such as
public Class<?>[] getParameterTypes();
and such as
public Class<?> getReturnType();
are not part of any interface, while they are extensively used.
The second drawback is that it fails to provide drop-in replacement. That is, I can't pass my dynamic proxy to the code that expects java.lang.reflect.Method.
Another approach is to use CGLIB or Javaassist. AFAIK, CGLIB can't proxy final class, does he? Can Javaassist proxy final class? How can I "remove" final identifier from the class? AFAIL, Javvassist can somehow do it...