A simple sample callback in Java


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();
    }
}

Recommended Posts

A simple sample callback in Java
3 Implement a simple interpreter in Java
Simple htmlspecialchars in Java
Java Callback Simple Sample Part2 Anonymous Class Example
CICS-Run Java application-(1) Run a simple sample app
Find a subset in Java
2 Implement simple parsing in Java
[Java] Draw a simple pattern
I made a simple calculation problem game in Java
[Personal memo] Make a simple deep copy in Java
Very simple input reception in Java
Try to make a simple callback
I created a PDF in Java.
Get stuck in a Java primer
1 Implement simple lexical analysis in Java
A Simple CRUD Sample Using Java Servlet / JSP and MySQL
Sample vending machine made in Java
What is a class in Java language (3 /?)
When seeking multiple in a Java array
[Creating] A memorandum about coding in Java
A simple sample of ArBiMap (two-way map)
Java creates a table in a Word document
Java creates a pie chart in Excel
What is a class in Java language (1 /?)
What is a class in Java language (2 /?)
Create a TODO app in Java 7 Create Header
Sample vending machine made in Java (classification)
Try making a calculator app in Java
Implement something like a stack in Java
Split a string with ". (Dot)" in Java
Creating a matrix class in Java Part 1
Sample to unzip gz file in Java
Partization in Java
[Java] Generics sample
java callback pattern
Java sample code 03
Changes in Java 11
Java GUI sample
Rock-paper-scissors in Java
Java sample code 04
Sample program that returns the hash value of a file in Java
Java sample code 01
Pi in Java
FizzBuzz in Java
I made a primality test program in Java
GetInstance () from a @Singleton class in Groovy from Java
Two ways to start a thread in Java + @
Read a string in a PDF file with Java
Create a CSR with extended information in Java
Create a simple bulletin board with Java + MySQL
A story about the JDK in the Java 11 era
How to display a web page in Java
java I tried to break a simple block
Create a simple batch processing framework in Eclipse.
[Android / Java] Operate a local database in Room
Measure the size of a folder in Java
Code to escape a JSON string in Java
Try to create a bulletin board in Java
A note when you want Tuple in Java
I wanted to make (a == 1 && a == 2 && a == 3) true in Java
I wrote a primality test program in Java