-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathProxy.java
More file actions
30 lines (20 loc) · 823 Bytes
/
Copy pathProxy.java
File metadata and controls
30 lines (20 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package proxy.jdk;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
public class Proxy implements InvocationHandler {
private Object proxyed;
public Proxy(Object proxy) {
this.proxyed = proxy;
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
System.out.println("defaultProxy is run");
return method.invoke(proxyed,args);
}
public static void main(String[] args) {
DefaultInterface defaultInterface = new DefaultInterface();
Proxy defaultProxy = new Proxy(defaultInterface);
Interface o =(Interface) java.lang.reflect.Proxy.newProxyInstance(Interface.class.getClassLoader(), new Class[]{Interface.class}, new Proxy(defaultInterface));
o.sayHi();
}
}