2017-12-10 16 views
-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 class MyInterceptor { 
    public static String intercept() { 
     return "intercept"; 
    } 
} 

답변

1

는 인터셉터 방법을 공개합니다. MyInterceptor는 중첩 클래스입니까? 어쩌면 최상위 클래스 인 경우 공용 정적 또는 공용으로 설정하십시오.
+0

여전히 내가 이상한 같은 문제 – Tirumalesh

+0

에 직면하고 있습니다 :

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"; } } 
kaos

+0

안녕하세요 카오스, 나는 MyInterceptor를 public으로 만들었고 작동 중입니다. 많은 감사합니다 :) – Tirumalesh