java模拟接口回调

来源:互联网 发布:下载视频软件 编辑:程序博客网 时间:2024/04/29 19:22
public class Test {
    public static void main(String[] args) {
        InterfaceReturn interfaceReturn=new InterfaceReturn();
        interfaceReturn.setonclick(new InterfaceReturn.MyInterface() {
            @Override
            public void onclick(int position) {
                // TODO Auto-generated method stub
                System.out.println(this);
            }
        });
    }

}

public class InterfaceReturn{
    
    MyInterface myInterface;
    
    public void  setonclick(MyInterface i){
        myInterface=i;
    }
    
    public void  loading(){
        if(null != myInterface)
            myInterface.onclick(0);
        System.out.println("InterfaceReturn------------->"+this);
    }

    public interface MyInterface{
        public void onclick(int position);
    }
}

0 0