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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:48:24+00:00 2026-06-11T23:48:24+00:00

I have a method that I want to call from two different places on

  • 0

I have a method that I want to call from two different places on the same class where in one it calls a dialog normally and on the other it calls the dialog with one disabled field on it.

I know that passing a flag on the call and making the test inside the method works but is there a more optmized way of doing it?
Is there any way to inside the method knowing where the call happened?

edit:

   // The part where you call the method passing a flag.
   showItemCustomDialog(true);
   showItemCustomDialog(false);

   // The dialog
   public void showItemCustomDialog(boolean flag) { 
       customDialog = new Dialog(this));
       field.setEnabled(flag);
   }

Is that a good example?

  • 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-11T23:48:25+00:00Added an answer on June 11, 2026 at 11:48 pm

    Ultimately you’re going to need to do some kind of test to know whether or not you need to disable the field, and you test on boolean values, so the easiest way to get that boolean is to simply pass it. Parameter passing of any kind, primitives, objects, etc., is relatively cheap, so performance wise, there isn’t really any issue with this.

    In terms of design, it makes sense to use the parameter since this is indeed the purpose of a boolean value, to indicate to do one thing or another whether it’s true or false.

    Any other solution you come up with is going to be either nasty or slow (I’m looking at you, Thread.currentThread().getStackTrace() people) and is going to require you to test some value, but you’ll have to calculate that value first, which takes time.

    If you really don’t want to pass the parameter, then maybe you can use some kind of state within the object to decide this, but ultimately that will just be a boolean field instead of a boolean parameter, so really, you’re just doing the same thing. Plus, if you run that code in any kind of concurrent system, then you’ll have to add synchronization, which just further increases code complexity you could have avoided by passing it as a parameter.

    I guess, long story short, just use a parameter. It’s sensible, readable, and anyone who reads your code will immediately understand what you did. Don’t do things in your code that are vague, that will hinder readability, etc. just because it will “do something cool” like make it so you don’t have to pass a parameter. Think of it like this: if someone wanted to call that method from some other method besides the ones you added, how long would it take them to figure out how to call it?

    Edit: One other option would be overloading. You could provide some common default-valued method and a method with the parameter. If you find that you enable the field more often than you disable it:

    public void showDialog() {
        showDialog(true);
    }
    
    public void showDialog(boolean fieldEnabled) {
        // Show the dialog
    }
    

    Then everywhere that opens the dialog with it enabled will call the first method (or the second with true), and the ones that want it to be disabled call the second one and have to pass false.

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

Sidebar

Related Questions

I have two different classes that have the same class as a private field.
I have two classes that inherit from the same base class but do not
I have a method in a class in another file that I want to
Okay, so I want to have a generic method that can read data from
I have a method song_link that calls link_to internally. I want the caller to
I have a layer based class that contains two sprites as children. Lets call
I want to call a method where two parametres are objects (one retrieve Person,
I have two separate classes, ClassA and ClassB, that derive from the same base
I have a list of methods that I want to call named Method1, Method2,
I have a method: myMethod() {} that I want to make accessible to javascript.

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.