// Continue on. Invoke the real method or constructor. InvocationResponse rsp = invocation.invokeNext(); System.out.println(Leaving + message); return rsp; } }
運行例子2 [code]POJO類將擴展一點,增加get()和set()方法。 public class POJO { public POJO() {} public void helloWorld() { System.out.println(Hello World!); }
private int counter = 0;
public int getCounter() { return counter; } public void setCounter(int val) { counter = val; } public static void main(String[] args) { POJO pojo = new POJO(); pojo.helloWorld(); pojo.setCounter(32); System.out.println(counter is: + pojo.getCounter()); } } TracingInterceptor將攔截對main(),POJO()和helloWorld()調用。輸出應該看起來如下: Entering constructor: public POJO() Leaving constructor: public POJO() Entering method: helloWorld Hello World! Leaving method: helloWorld [/code]