美文网首页
java回调

java回调

作者: android_Pie | 来源:发表于2023-10-18 09:55 被阅读0次

    package com.company;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collections;
    import java.util.List;
    public class Main {

    public static class A {
    
        private void toShow(){
            B.show();
            B.BSetCallBack(callBack);
        }
    
        private B.BCallBack callBack = new B.BCallBack() {
            @Override
            public void callback(String num) {
            System.out.println("num:"+num);
            }
        };
    
    }
    
    public static class B {
        private static String num;
    
        public static void show() {
            // do show
            // ..
            num = "1025";
        }
    
        public static void BSetCallBack (BCallBack callBack) {
            callBack.callback(num);
        }
    
        interface BCallBack {
            void callback(String num);
        }
    }
    
    public static void main(String[] args) {
        // write your code here
          A a=new A();
          a.toShow();
    
    }
    

    }

    相关文章

      网友评论

          本文标题:java回调

          本文链接:https://www.haomeiwen.com/subject/xarqidtx.html