LucaW
LucaW

Reputation: 79

Refactoring when a method has been moved into another (static) class

I had my clearScreen method in my Settings class and moved it into my Formats class. Since ive used it many times already i dont really want to change it every time. When I try to rename it using refactoring though, it gives me these errors: "Compilation untit Formats.java already exists" and "Type named Formats already exists in Package(default package)"

Is there any way to refactor the class thats being called?
If it isnt clear what i mean, it would go from

Settings.clearScreen();

to

Formats.clearScreen();

Upvotes: 1

Views: 63

Answers (1)

Andy Turner
Andy Turner

Reputation: 140534

The easiest way is to:

  1. Add the method in the new location
  2. Change the existing method to call the new method:

    class Settings {
      // ...
      void clearScreen () {
        Formats.clearScreen();
      }
      // ...
    }
    
  3. Select clearScreen in Settings and inline it.

Upvotes: 1

Related Questions