Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8678131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:38:05+00:00 2026-06-12T20:38:05+00:00

I have some misunderstanding about terms of delegates and callbacks in Java. class MyDriver

  • 0

I have some misunderstanding about terms of delegates and callbacks in Java.

class MyDriver {

    public static void main(String[] argv){
        MyObject myObj = new MyObject();
        // definition of HelpCallback omitted for brevity
        myObj.getHelp(new HelpCallback () {
            @Override
            public void call(int result) {
                System.out.println("Help Callback: "+result);
            }
        });
    }
}

class MyObject {

    public void getHelp(HelpCallback callback){
        //do something
        callback.call(OK);
    }
}

Is it callback or delegate (Are delegates and callbacks the same or similar?)?

How to implement then another one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T20:38:06+00:00Added an answer on June 12, 2026 at 8:38 pm

    This is a callback. According to Wikipedia:

    In computer programming, a callback is a reference to a piece of executable code that is passed as an argument to other code.

    So let’s look at the executable code:

    public void getHelp(HelpCallback callback){
        //do something
        callback.call(OK);
    }
    

    Here, the callback argument is a reference to an object of type HelpCallback. Since that reference is passed in as an argument, it is a callback.

    An example of delegation

    Delegation is done internally by the object – independent of how the method is invoked. If, for example, the callback variable wasn’t an argument, but rather an instance variable:

    class MyDriver {
    
        public static void main(String[] argv){
            // definition of HelpStrategy omitted for brevity
            MyObject myObj = new MyObject(new HelpStrategy() {
                @Override
                public void getHelp() {
                    System.out.println("Getting help!");
                }
            });
            myObj.getHelp();
        }
    
    }
    
    class MyObject {
        private final HelpStrategy helpStrategy;
    
        public MyObject(HelpStrategy helpStrategy) {
            this.helpStrategy = helpStrategy;
        }
    
        public void getHelp(){
            helpStrategy.getHelp();
        }
    }
    

    … then it would be delegation.

    Here, MyObject uses the strategy pattern. There are two things to note:

    1. The invocation of getHelp() doesn’t involve passing a reference to executable code. i.e. this is not a callback.
    2. The fact that MyObject.getHelp() invokes helpStrategy.getHelp() is not evident from the public interface of the MyObject object or from the getHelp() invocation. This kind of information hiding is somewhat characteristic of delegation.

    Also of note is the lack of a // do something section in the getHelp() method. When using a callback, the callback does not do anything relevant to the object’s behavior: it just notifies the caller in some way, which is why a // do something section was necessary. However, when using delegation the actual behavior of the method depends on the delegate – so really we could end up needing both since they serve distinct purposes:

        public void getHelp(HelpCallback callback){
            helpStrategy.getHelp(); // perform logic / behavior; "do something" as some might say
            if(callback != null) {
                callback.call(); // invoke the callback, to notify the caller of something
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I think I must have some misunderstanding about the datanodes in Hadoop Cluster. I
I have some misunderstanding about the gslice function. Definition from MSDN states: gslice defines
I have some misunderstanding about the tellp and seekg functions. For example, when I
In explanations I've read about public key cryptography, it is said that some large
I may have some misunderstanding regarding the use of the UINavigationControllerDelegate protocol. Here is
i am using c++ and i have some trouble about pointers i know that
Even after reading the documentation , I seem to have a fundamental misunderstanding about
I think I must be misunderstanding something about R's system.time() function. If I have
What is my misunderstanding about the way that vertical-align:middle; works? I have posted (
I have some misunderstanding of the processor register concepts. There is a register with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.