【初心者】Java質問・相談スレ24【大歓迎】
■ このスレッドは過去ログ倉庫に格納されています
0061名無しさん@Monalipse
NGNGN88Basic上がりか?そういう発想は20年前に捨ててくれ。
いわゆるコールバックをしたいのなら、呼び出し元のオブジェクトへの参照を渡せばよい。
こんな感じ。
public interface ICaller{
public int callbackMethod(int arg);
}
public class Foo implements ICaller{
public void aMethod(){
Bar b = new Bar();
System.out.println(b.buz(12));
}
public int callbackMethod(int arg){
return arg * 10;
}
}
public class Bar{
public int buz(ICaller caller){
..;
int ret = caller.callbackMethod(10);
..;
return ret;
}
}
■ このスレッドは過去ログ倉庫に格納されています