您的位置:首页 > 编程语言 > Java开发

java模拟接口回调

2016-05-19 20:51 489 查看
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);

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: