接口回调

来源:互联网 发布:易成运营商数据分析 编辑:程序博客网 时间:2024/06/06 18:14
package com.test.study.callback;

public class Test {
    
    
    public abstract class  CallBack2<T> {
        abstract void execute(T t);
        
    }
    
    public interface  CallBack3<T> {
        void execute(T t);
        
    }
    
    
    public static void main(String[] args) {
        
        Test test=new Test();
        
        test.proccess();
        
        //回调内部类
        test.print2(new CallBack3<String>(){

            @Override
            public void execute(String t) {
                System.out.println("12344");
            }

            
        });
        
       
    }
    
    
    public void proccess()
    {
        Test test=new Test();
        //回调内部类
        test.print(new CallBack2<String>(){

            @Override
            void execute(String t) {
                System.out.println("12344");
            }
            
            void send()
            {
                System.out.println("0000");
            }

            
        });
        
    }
    
    public void print2(CallBack3 c)
    {
        System.out.println("=======");
        c.execute("");
    }
    
    
    public void print(CallBack2 c)
    {
        System.out.println("=======");
        c.execute("");
    }

}

原创粉丝点击