java回调

2023-10-18  本文已影响0人  android_Pie

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();

}

}

上一篇下一篇

猜你喜欢

热点阅读