簡(jiǎn)單的描述JDK的動(dòng)態(tài)代理實(shí)現(xiàn)調(diào)用攔截器中的方法(從李剛老師的<>中學(xué)到)
1.JDK能對(duì)實(shí)現(xiàn)了接口的實(shí)例來(lái)生成代理,因此首先創(chuàng)建一個(gè)接口.
//interface person
package cn.edu.hld;
public interface Person
{
public void info() ;
public void run() ;
}
2.為了在后面實(shí)現(xiàn)動(dòng)態(tài)代理,因此提供一個(gè)Person接口的實(shí)現(xiàn)類.
//類PersonImpl .java
package cn.edu.hld;
public class PersonImpl implements Person
{
public void info()
{
// TODO Auto-generated method stub
System.out.println("我是thtwin") ;
}
public void run()
{
// TODO Auto-generated method stub
System.out.println("我想跑得快一些!");
}
}
1.JDK能對(duì)實(shí)現(xiàn)了接口的實(shí)例來(lái)生成代理,因此首先創(chuàng)建一個(gè)接口.
//interface person
package cn.edu.hld;
public interface Person
{
public void info() ;
public void run() ;
}
2.為了在后面實(shí)現(xiàn)動(dòng)態(tài)代理,因此提供一個(gè)Person接口的實(shí)現(xiàn)類.
//類PersonImpl .java
package cn.edu.hld;
public class PersonImpl implements Person
{
public void info()
{
// TODO Auto-generated method stub
System.out.println("我是thtwin") ;
}
public void run()
{
// TODO Auto-generated method stub
System.out.println("我想跑得快一些!");
}
}