A
A
artshelom2016-12-07 11:22:06
Java
artshelom, 2016-12-07 11:22:06

How to do for callback in JAVA?

Good afternoon. I can't figure out how to make a callback in a telegram bot

public class Callback{
    interface Call{
        void callingBack();
        void callG();
    }
    Call call;
    public void registerCal(Call call){
        this.call = call;
    }
    public void doSom(){
        JOptionPane.showMessageDialog(null, "Выполняется работа");
        String text = "Привет";
        System.out.println(text);
        call.callingBack();
        JOptionPane.showMessageDialog(null, "Выполняется работа 2");
        text = "Пока";
        call.callingBack();
        System.out.println(text);
    }
}
class MyClass implements Callback.Call {
    @Override
    public void callingBack() {
        System.out.println("Тут Работает");
        try {
            Thread.sleep(50000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public void callG() {
        System.out.println("ткк");
    }
}

public class Menu {
    public static void main(String[] args) {
        Callback callback = new Callback();
        MyClass myClass = new MyClass();
        callback.registerCal(myClass);
        callback.doSom();
    }
}

You need to make sure that the call comes from another method. And I don't know how to do it

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
developer007, 2016-12-07
@developer007

Create a simple project and play only with callbacks until you understand how it works stackoverflow.com/questions/18279302/how-do-i-perf...
As I understand it, you need to notify the object that another object has completed execution tasks?
Use the observer - https://ru.wikipedia.org/wiki/%D0%9D%D0%B0%D0%B1%D...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question