2017年4月24日月曜日

Java interface Callback

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

public class Main {
    public static void main(String[] args) throws Exception {
    Oset oset = new Oset();
    oset.setont(new onTest(){
        public void getx(){
            System.out.println("----------------interface Callback---------------");
        }
    });

    try{
        Thread.sleep(1000);
    }catch(Exception e){
     
    }
    oset.methods();
    }
}


interface onTest{
    public void getx();
}

class Oset {
    private onTest ont;
    public void setont(onTest ont){
        this.ont = ont;
    }
 
    public void methods(){
        System.out.println("--------------methods------------------");
        ont.getx();
    }
}

Demo
https://paiza.io/projects/uWqAgbv37VXi3LEWkS4WlQ


0 件のコメント: