How to create proxy in java
-
How do they create proxy of a class in java. Do they create the proxy on as needed basis or they create it and have it around forever.
-
Answer:
You can create proxies in two basic ways: using the JDK mechanism, by interface. Take a look at http://download.oracle.com/javase/6/docs/api/java/lang/reflect/Proxy.html. using some byte-code generation/manipulation library, on a concrete class. Take a look at http://cglib.sourceforge.net/ and http://www.csg.is.titech.ac.jp/~chiba/javassist/ Apache has a nice utility: http://commons.apache.org/proxy/. It wraps many mechanisms and frameworks for creating proxies. This is all about dynamic proxies - i.e. those created at runtime. For static proxies - see http://en.wikipedia.org/wiki/Proxy_pattern Note that you are not making a proxy of a class - you are making a proxy of an object.
javaguy at Stack Overflow Visit the source
Other answers
I agree with the comments that the question is a little vague. However, I'd suggest you look at some of the mocking frameworks such as easymock and mockito. Their source code is available and their core functionality is creating proxies of class and interfaces. So they are good concrete examples of how to go about creating proxies.
drekka
Related Q & A:
- how to Create a Java Package from MATLAB Code?Best solution by Stack Overflow
- How to create RSS feed in Java?Best solution by Stack Overflow
- how to create a new syntax in java?Best solution by Stack Overflow
- How to create a java applet?Best solution by Stack Overflow
- How to create this Java program?Best solution by ChaCha
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.