-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMyBean.java
48 lines (37 loc) · 1 KB
/
MyBean.java
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package util;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
/**
*
*/
interface BeanInterface{
public int calculate ();
}
public class MyBean implements BeanInterface{
private int value;
public MyBean( int value ) {
this.value = value;
}
public int getValue() {
return value;
}
public void setValue( int value ) {
this.value = value;
}
@Override
public int calculate (){
return this.value;
}
public static void main( String[] args ) {
BeanInterface proxyInstance = (BeanInterface) Proxy.newProxyInstance(MyBean.class.getClassLoader(), new Class[]{BeanInterface.class}, new MyHandler());
proxyInstance.calculate();
}
}
class MyHandler implements InvocationHandler{
@Override
public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable {
System.out.println("hi");
return method.invoke(proxy, args);
}
}