If you mean the interception method, there are two options
1) java.lang.reflect.Proxy. Below, the test makes proxies for the list and intercepts method calls. Please note that it only works with interfaces.
class Handler implements java.lang.reflect.InvocationHandler { Object target; Handler(Object target) { this.target = target; } @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { System.out.println("Before " + method.getName()); Object res = method.invoke(target, args); System.out.println("After " + method.getName()); return res; } } List list = new ArrayList(); List proxy = (List) Proxy.newProxyInstance(Test.class.getClassLoader(), new Class[] { List.class }, new Handler(list)); proxy.add(1);
prints
Before add After add
2) Aspect-oriented programming. The easiest way to start using it, in my opinion, is Spring http://static.springsource.org/spring/docs/3.2.x/spring-framework-reference/html/aop.html
source share