31 lines
729 B
Java
31 lines
729 B
Java
package com.rootcloud.utils;
|
|
|
|
import java.lang.reflect.Proxy;
|
|
|
|
public class StudentProxy implements Person {
|
|
|
|
private Student student;
|
|
|
|
public StudentProxy(Person person) {
|
|
this.student = (Student) person;
|
|
}
|
|
|
|
@Override
|
|
public void giveMoney() {
|
|
this.student.giveMoney();
|
|
}
|
|
|
|
|
|
public static void main(String [] args){
|
|
Student student = new Student();
|
|
student.setName("张三");
|
|
StudentProxy studentProxy = new StudentProxy(student);
|
|
studentProxy.giveMoney();
|
|
|
|
|
|
Person person =(Person)Proxy.newProxyInstance(Person.class.getClassLoader(),new Class<?>[]{Person.class},new StuInvocationHandler<Person>(student));
|
|
|
|
person.giveMoney();
|
|
}
|
|
}
|