-1
を取得しています:私は私がやっているのミスを知らない私は、エラー、次の取得していますjava.lang.IllegalArgumentExceptionが
java.lang.IllegalArgumentException: None of [static java.lang.String com.runtime.MyInterceptor.intercept()] allows for delegation from public java.lang.String java.lang.Object.toString()
。
public void interceptMethod() throws InstantiationException, IllegalAccessException {
Class<?> dynamicType = new ByteBuddy().subclass(Object.class)
.method(ElementMatchers.named("toString"))
.intercept(MethodDelegation
.to(MyInterceptor.class))
.make()
.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
if (dynamicType.newInstance().toString().equals("intercept")) {
System.out.println("method intercept() is intercepted by byteBuddy");
} else {
System.out.println("Failed to intercept the method toString()");
}
}
class MyInterceptor {
static String intercept() {
return "intercept";
}
}
まだ私は奇妙だ、同じ問題に直面して – Tirumalesh
よ私はその変更でそれを実行すると、あなたのコードは動作しています。 MyInterceptorはネストされたクラスですか?たぶんそれはトップレベルのクラスの場合は、パブリック静的またはパブリックにしようとします。 – kaos
こんにちはKaos、私はMyInterceptorをpublicとして作っています。あなたのために多くのおかげで:) – Tirumalesh