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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:40:20+00:00 2026-05-25T19:40:20+00:00

I have a Java method. For the sake of being a public forum, I’m

  • 0

I have a Java method. For the sake of being a public forum, I’m going to say that my method is called foo

Bar foo(Boolean flag)
{
   flag = true;
   return new Bar();
}

I get a warning by setting flag. Unfortunately, I have not found a way to suppress such a warning. Is there a “right” way of doing this? Now I know there are some who will say to simply not use an out parameter. Trust me when I say that I have a good reason for doing it this way. If there’s no way around the warning without doing something crazy, I suppose that’s fine. I just don’t like checking in code with warnings.

  • 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-25T19:40:21+00:00Added an answer on May 25, 2026 at 7:40 pm

    You’re getting a warning because your assignment is doing nothing useful. You shouldn’t check this code in because it doesn’t do what you think it does. For example:

    Boolean x = false;
    Bar bar = foo(x);
    System.out.println(x); // Still false
    

    Your code is setting the value of the flag parameter, which won’t change anything about the value which is passed in. Java strictly uses pass-by-value, including when it’s passing reference (which it’s doing here).

    If Boolean were mutable you could write:

    // Not actually valid
    flag.setValue(true);
    

    and change the contents of the object that x referred to in the first snippet of code – but all the wrapper types in Java are immutable.

    Now it’s not really clear what your higher level purpose is, but basically it’s not going to be accomplished by the code you’ve given – so heed the warning, and change your approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Java method something like this public boolean ReadBool(String ValueName, Boolean Value)
I have a Java method that accepts a Long value: (in Java) public void
I have a Java method that takes 3 parameters, and I'd like it to
Suppose I have a Java method that returns a HashMap object. Because a LinkedHashMap
I need a Regex that will match a java method declaration. I have come
I have a Java method that repeatedly evaluates the following expression in a very
I have a java class ( Test ) with a public method which returns
I have a Java method with the following signature: public <T> List<HtmlOptionsComposite> convertToHtmlOptionsCompositeList (List<?
I have a java method that should check through an ArrayList and check if
I have a Java method takes an argument of type Map<Long, Foo> . I

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.