2017年2月28日火曜日

Java CallBack 练习

Java CallBack 练习

https://paiza.io/projects/J4kb3mqHFWTylgPFh_q-sw

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        Text1 tt1 = new Text1();
        tt1.t1(new Text1.CallBack(){
            public void gets(String x){
                System.out.println(x);
            }
            public void gety(String y){
                System.out.println(y);
            }
        });
    }
}

class Text1{
    interface CallBack{
        public void gets(String x);
        public void gety(String y);
    }

    public void t1( CallBack cb){
        int i = 6;
        for(; i < 200; i++){
        }
        if(i%2 == 0){
            cb.gets("x" + i + "");
        }else{
            cb.gety("y" + i + "");
        }
    }
}

0 件のコメント: