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 8233867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:16:34+00:00 2026-06-07T18:16:34+00:00

I have a little question here. private boolean isSomethingTrue(String param) { boolean result =

  • 0

I have a little question here.

private boolean isSomethingTrue(String param) {
    boolean result = false;
    myService.hasAlerts(param,new Callback<Boolean>(
        @Override
        public void onSuccess(Boolean hasAlerts) {
            result = hasAlerts;
        }
    });
    return result;
}

On this code, how can i return the boolean hasAlerts that is received in the callback?
This doesn’t work because the result variable is not final.
But when it’s final, it can’t be modified so…

I’ve done something like that:

private boolean isSomethingTrue(String param) {
    class ResultHolder {
        boolean result=false;
    }
    final ResultHolder resultHolder = new ResultHolder();
    myService.findBoolean(param,new Callback<Boolean>(
        @Override
        public void onSuccess(Boolean hasAlerts) {
            resultHolder.result = hasAlerts;
        }
    });
    return resultHolder.result;
}

But is there a simpler solution to handle such a case?

I’ve found this problem while trying to call a GWT RPC service.

  • 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-07T18:16:37+00:00Added an answer on June 7, 2026 at 6:16 pm

    I can think of a few variations–none of them particularly exciting. You could merge the result holder and callback into a single class and make it static if you could use it elsewhere, but it’s not really an improvement.

    private boolean isSomethingTrue(String param) {
        class MyCallback implements Callback<Boolean> {
            boolean result = false;
            @Override
            public void onSuccess(Boolean hasAlerts) {
                result = hasAlerts;
            }
        }
        final MyCallback callback = new MyCallback();
        myService.findBoolean(param, callback);
        return callback.result;
    }
    

    You could implement a generic synchronous Future, but that might be misleading.

    Finally, if you’re doing this often you could genericize the value holder.

    public class Result<T> {
        private T value;
        public void set(T value) { this.value = value; }
        public T get() { return value; }
    }
    
    private boolean isSomethingTrue(String param) {
        final Result<Boolean> result = new Result<Boolean>();
        myService.findBoolean(param,new Callback<Boolean>(
            @Override
            public void onSuccess(Boolean hasAlerts) {
                result.set(hasAlerts);
            }
        });
        return result.get();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A little stuck here. I have a simple question I guess. Given the following
I have found a similar question here , but my intent is little different.
I have little question about how web browser retrieve webpage? I know this User
I have little question. I found this on internet: Type t = typeof(MyClass); MethodInfo[]
I have a little question I want to click on my smileys and insert
I have a little question to community. Does ASP.NET MVC allow to execute an
I have this little question that's been on my mind for a while now.
i have a little question, regarding to slideup and slidedown, the problem is in
Following the good jQuery Plugins/Authoring instructions I have a little question (function($){ // Default
I have little bit longer question for you - but hope answer will be

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.