Java interface Callback 2
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception{
T1 t = new T1();
try{
Thread.sleep(1000);
}catch(Exception e){
}
t.st();
}
}
class T1 implements onTest{
public Oset o;
public T1(){
o = new Oset();
o.setont(this);
}
public void st(){
o.methods();
}
public void getx(){
System.out.println("--------implements onTest--------");
}
}
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/l2lBiluXHzRmjoKsj-cLBA
0 件のコメント:
コメントを投稿