Difference between revisions of "Dynamic Proxy"
From ADempiere
This Wiki is read-only for reference purposes to avoid broken links.
m |
m |
||
Line 1: | Line 1: | ||
Example of Dynamic Proxy | Example of Dynamic Proxy | ||
− | < | + | <code><pre> |
− | + | ||
public TestInterface { | public TestInterface { | ||
public void print(String value); | public void print(String value); | ||
Line 26: | Line 25: | ||
//to stdout | //to stdout | ||
− | </ | + | </pre></code> |
Revision as of 11:00, 21 May 2007
Example of Dynamic Proxy
public TestInterface {
public void print(String value);
}
public TestProxy extends InvocationHandler {
public Object invoke (Object proxy, Method method, Object[] args) {
if (method.getName().equals("print")) {
System.out.println(args[0]);
return null;
}
return null;
}
}
TestInterface instance = Proxy.newProxyInstance(
TestInterface.class.getClassLoader(),
new Class[] {TestInterface.class},
new TestProxy());
Instance.print("Hello World!"); // prints "Hello World!"
//to stdout