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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T08:45:59+00:00 2026-05-27T08:45:59+00:00

Given I have code like the following: void foo() { String str = hello;

  • 0

Given I have code like the following:

void foo() {
  String str = "hello";

  a(str, 1);
  b(str, true);

  a(str, 2);
  b(str, false);
}

I would like to extract a new method c like:

void foo() {
  String str = "hello";

  c(str, 1, true);
  c(str, 2, false);
}

However, the automated Extract Method refactoring will only extract one of the a/b pairs. My guess is that it dislikes the differing constants. I can work around this by extracting a local variable first, then extracting the method, then inlining the previously extracted variable, but I still have to find all the instances by hand. With that amount of work, I might as well just make the full change myself when I am looking at each part.

Is there a trick I am missing to let Eclipse know to search a little harder to extract this type of code?

  • 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-27T08:45:59+00:00Added an answer on May 27, 2026 at 8:45 am

    Yes, you need to extract your constants into variable that you can put in the top to tell your tool to pass them as arguments to the extracted method.

    void foo() {
      String str = "hello";
      int constant = 1;
      boolean boolValue = true;
      a(str, constant);
      b(str, boolValue);
    
      constant = 2;
      boolValue = false;
      a(str, constant);
      b(str, boolValue);
    }
    

    Doing an extract method should give the following:

    public void c(String str, int constant, boolean boolVal){
        a(str, constant);
        b(str, boolVal);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

given i have the following block of code (function(){ var mb = { abc:function(){
I have the following code (generates a quadratic function given the a, b, and
I have the following html code (in the given order) <div id=content>...</div> <div id=footer>...</div>
Assume we have the following, given code: class T; // with T::~T is virtual
Given the following methods: // Method 1 void add(const std::string& header, bool replace); //Method
I have multiple chunks of code similar to the following: void GetPerson(Action<PersonView, Exception> callback);
If I have a function void Foo(params int[] bar){} The following runs fine: int[]
I have a code like this below, which gives me a $link that equals
I have the following code, which will not work. The javascript gives no errors
Given you have the following class (bad C#, but you get the drift): public

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.