When refactoring, one thing that sometimes changes is a method’s signature (ie. its return type, number of arguments, argument types and order).
For some it may not happen that often, but the job becomes difficult when you have a dozen or more classes that call that method. All of them need to be changed to match the new signature and this can take a long time to change.
Fortunately, Eclipse has a refactoring called Change Method Signature that makes this easy, allowing a signature change in almost no time across any number of classes. This can be a huge timesaver when you need it and save you hours of frustration trying to fix red crosses in Eclipse.
How to change a method signature
The refactoring is easy to invoke. The fastest way to do this is to position the cursor on the method’s declaration or any of it’s calls and then press Alt+Shift+C (or alternatively select Refactor > Change Method Signature from the application menu). This can only be invoked on methods for which you own the code.
In the next video I show an example of adding a new String argument called message to the method process as the second argument. Notice how Eclipse automatically shifts all other arguments up by one. Then we’ll remove the int argument. The two affected classes are below each other so you can see the magic in action.
Notes:
- To reorder the arguments, just press the Up/Down buttons.
- You can specify a default value for the new argument. This is the default value that Eclipse will give all method calls. Normally null or another sensible default will do.
- You can preview the changes before you accept them. Eclipse shows you all affected classes and allows you to compare the current and soon-to-be code.
- Eclipse has Content Assist inside the refactoring dialog, meaning that you can press Ctrl+Space in the Type column to see a list of object types that match the name you’ve typed.
- You can change the return type and even the name of the method. If you just want to rename a method, rather use the Rename refactoring (Alt+Shift+R).
Related Tips
Here are some other tips that might interest you:
- The example video shows two editors below each other. You can find out how to see the same editor side by side in Eclipse.
- While you’re refactoring code, check out some other refactorings that Eclipse provides that could help you. You can also have a look at other editing tips that may interest you.
- You can remap the keyboard shortcut if you find Alt+Shift+C doesn’t work for you (the command’s name is Change Method Signature). There are also other keyboard shortcuts you can check out as well to make coding a lot faster, meaning you don’t have to reach for that mouse to refactor you code.
Filed under: Editing, Refactoring



















Thanks, exactly what I was looking for.