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

  • Home
  • SEARCH
  • 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 6361867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:49:57+00:00 2026-05-24T23:49:57+00:00

I am implementing an interface. I have two functions that I have to implement

  • 0

I am implementing an interface.

I have two functions that I have to implement A and B. A checks the file is not corrupt and return then B processes the file and returns. after B return function C runs, I have no control over C as I am just implementing A and B.

The problem is that B takes a long time to run and C needs it return value to run. Ideally I would split B into B and D and put all the stuff that C dose not need to run into D. As this is impossible I want to know if it is possible to return a value from B so C can run but afterwards then have B run more code.

C cannot be called from B.

  • 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-05-24T23:49:58+00:00Added an answer on May 24, 2026 at 11:49 pm

    A must call B and C You want B to do some processing, C to be called and B to continue processing.

    The simplest approach is to have

    A called a method on B which opens the file and does some processing, and leaves anything open which is need later. A calls C and then calls another method on B which finishes the processing. This means B must know when to stop and return so C can be called.

    The way around this is to use a listener interface below.

    class A {
       void method(B b, C c) {
          b.function(new Listener() {
              public void onValue(long num) { // or any event type
                 if (num > 100) C.something();
              }
          });
       }
    }
    

    This way B has no idea when C will be called.


    You can implement a listener interface which you pass to the function and it can “return” multiple values. However once a function actually returns it is no longer running.

    This function can run in another thread or the same thread.

    interface Listener {
         public void onValue(long num);
         public void onError(Exception e);
         public void onEndOfData();
    }
    
    public void function(Listener l) {
        try {
           for(int i=0;i<10;i++) l.onValue(i);
    
           // read a file 
        } catch (Exception e) {
           l.onError(e);
        } finally {
           l.onEndOfData();
        }
    }
    

    put another way instead of doing something like

    // only one value.
    long value = function();
    System.out.println("value returned was "+value);
    

    you can do

    // any number of values can be returned 
    // and the function can keep processing.
    function(new Listener() {
        public void onValue(long value) {
            System.out.println("value returned was "+value);
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interface and two objects implementing that interface, massively simplied; public interface
I have noticed that doing actions like implementing an interface, that a small rectangle
I have an interface named SHAPE . CIRCLE and RECTANGLE are two classes implementing
I have an object that implements two interfaces... The interfaces are: public interface IObject
I have an Interface and two Classes which are implementing the Interface. public interface
I have an interface with several events I have base class implementing the interface
If I have an object implementing the Map interface in Java and I wish
Suppose I'm implementing an MVP pattern and I have a view interface as such:
When implementing an interface in eclipse, it has a really nice feature that lets
I'm implementing an interface that has functionality similar to a table that can contain

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.