• No replies
1 Post

Pinned topic How does this thing work?

‏2008-06-30T08:30:00Z |
Reading the following article I got some questions:

The article mentions that:
"Because proxy classes do not have accessible names, they cannot have constructors, so they must instead be created by factories."

But in an example later, the author has done this:

If you wrap a HashSet with a logging proxy and execute the following simple test program:

Set s = newLoggingProxy(Set.class, new HashSet());
if (!s.contains("four"))

It seems to create proxy using constructor only. Where is the code that generates proxy using factory method (where is the call of Proxy.newInstance())?

Moreover, in another example later the author has done something like this:

public class JavaBeanProxyFactory {


public static<T> T getProxy(Class<T> intf,
Map<String, Object> values) {
return (T) Proxy.newProxyInstance
new Class[] { intf }, new JavaBeanProxy(values));

While in a previous example the author did this:

public class SetProxyFactory {

public static Set getSetProxy(final Set s) {
return (Set) Proxy.newProxyInstance
new Class[] { Set.class },
new InvocationHandler() {
public Object invoke(Object proxy, Method method,
Object[] args) throws Throwable {
return method.invoke(s, args);

Now the question is which classloader should we use in the newProxyInstance method? ProxyFactory's classloader or the classloader of the class to be proxy-ed?

Thanks in advance.