Generating java proxy class in Eclipse
Is there a way in Eclipse to generate a proxy class (as in proxy pattern, not a remote call)? Something along the lines of this
public class FooBar{
public int getBiz(){
return 1234;
}
}
generates
public class FooBarProxy{
protected FooBar foobar;
public FooBarProxy(FooBar f) {...}
public int getBiz(){
开发者_Python百科 return foobar.getBiz()
}
}
Create the proxy class yourself, and add the FooBar instance variable. Select the variable, right click-->source-->generate delegate methods
Why not use java's built in dynamic proxy. It generates a proxy at runtime:
- implement your proxy logic by implementing java.lang.reflect.InvocationHandler
- create a dynamic proxy; see http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Proxy.html (example included)
精彩评论