public class MyInvocationHandler implements InvocationHandler {
private Object target
MyInvocationHandler(Object target){
this.target=target
}
public static void main(String[] args) {
MyInvocationHandler invocationHandler=new MyInvocationHandler(new ArrayList<>())
Collection collection= (Collection) Proxy.newProxyInstance(Collection.class.getClassLoader(),new Class[]{Collection.class},invocationHandler)
collection.add("abc")
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("start...")
Object object= method.invoke(target, args)
System.out.println("end...")
return object
}
}