Skip to content

Commit

Permalink
added support for proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
n9Mtq4 committed Aug 5, 2015
1 parent d942195 commit 6891504
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions src/com/n9mtq4/reflection/EnhancedProxy.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.n9mtq4.reflection;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

/**
* Created by will on 8/5/15 at 4:13 PM.
*/
public class EnhancedProxy implements InvocationHandler {

public static <E> E newInstance(Object obj, EnhancedInvocationHandler handler) {
return (E) Proxy.newProxyInstance(obj.getClass().getClassLoader(), obj.getClass().getInterfaces(), new EnhancedProxy(obj, handler));
}

private Object obj;
EnhancedInvocationHandler handler;

public EnhancedProxy(Object obj, EnhancedInvocationHandler handler) {
this.obj = obj;
this.handler = handler;
}

@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

return handler.invoke(obj, proxy, method, args);

}

public interface EnhancedInvocationHandler {

Object invoke(Object obj, Object proxy, Method method, Object[] args);

}

}

0 comments on commit 6891504

Please sign in to comment.