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.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
You can create proxies in two basic ways:
java.lang.reflect.Proxy
.Apache has a nice utility: commons-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 wikipedia about the proxy pattern
Note that you are not making a proxy of a class - you are making a proxy of an object.
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.