Why jdk dynamic proxy invoke InvocationHandler.invoke "toString" method when debug every step over mode

595 Views Asked by At

When I use jdk dynamic proxy ,seems

Object proxy = Proxy.newProxyInstance(Thread.currentThread().getContextClassLoader(),
                    new Class<?>[] { xx }, handler);

When I debug the program ,step over one by one, handler variant will invoke its method following with "toString" method

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    }
    if (method.getName().equals("toString")){
        System.out.println( " toString " +args);//**executed every step over line,why??**
        return method.invoke(target,args);
    }

But it is is no problem when not debug mode.

1

There are 1 best solutions below

0
On

enter image description here

I guess IDE need to display the info in the red box, this leads to invoking of the object's toString() method.