Java 回调
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;
public class Main {
public static void main(String[] args) throws Exception {
for(int i=0; i < 10; i++){
System.out.print(i);
}
////////////////////////////////////
new Thread(new Runnable(){
public void run(){
Test t = new Test();
t.relist(new Test.CallBack(){
public void getdata(List<String> list){
System.out.println(list);
}
});
}
}).start();
///////////////////////////////////
///////////////////////////////////
// Test t = new Test();
// t.relist(new Test.CallBack(){
// public void getdata(List<String> list){
// System.out.println(list);
// }
// });
///////////////////////////////////
for(int i=0; i < 10; i++){
System.out.print(i);
}
}
}
class Test{
private List<String> ls;
public interface CallBack{
public void getdata(List<String> list);
}
public void relist(CallBack calback){
ls = new ArrayList<String>();
for(int i = 0; i< 10; i++){
ls.add("add" + i);
}
calback.getdata(ls);
}
}
https://paiza.io/projects/HaU5z4cE88fPD8xvSeUznA
0 件のコメント:
コメントを投稿