Javaで署名の本質を抽出する方法を探しています。その理由は、java.lang.reflect.Proxiesのマップで一意のキーとして署名を使用したいためです。
このコードで:
public interface MyInterface {
public int compute(String s);
}
...
public static void main (String... args) throws Exception {
InvocationHandler handler = ...;
MyInterface i = (MyInterface) Proxy.newProxyInstance(
Beans.class.getClassLoader(),
new Class<?>[] { MyInterface.class },
handler);
Method m1 = MyInterface.class.getMethod("compute", String.class);
Method m2 = i.getClass().getMethod("compute", String.class);
System.out.printf("%b%f", m1.equals(m2));
}
結果は明らかに誤りです。
このコードは、InvocationHandler内で必要になるため、使用するコードではありませんが、プロキシの実装とインターフェイスに関して、取得method.getName()
してmethod.getParameterTypes()
十分か、それとも使用する必要があるかどうか疑問に思っています。method.getTypeParameters()
method.getParameterAnnotations()
要するに:インターフェースとそのjava.lang.reflect.Proxy実装で同じメソッドシグネチャを取得する方法は?