4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Java でコールバックの簡単サンプル

Last updated at Posted at 2019-04-02

interface Callback{
    void call();
}

class A implements Callback{
    private B b;

    public A(){
        b = new B();
        b.registerCallback(this);
    }    

    // Implementation of the callback interface
    public void call(){

    }
}

public class B
{
    private Callback callbackoNotify;

    public class registerCallback(Callback callback)
    {
        callbackoNotify = callback;
    }

    public void doTask()
    {  
        //do some stuff...
        callbackNotify.call();
    }
}
4
3
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?