dimanche 10 décembre 2017

I'm getting java.lang.IllegalArgumentException

i'm getting ****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()**** dont know what mistake i'm doing..

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





Aucun commentaire:

Enregistrer un commentaire