Changing a Method's Signature
See Also
The Change Method Parameters command enables you to alter the signature of a
method and have those changes propagated in all of the code that calls this method.
Specifically, you can:
To add a parameter to a method:
- Right-click the method in the Source Editor and choose
Refactor > Change Method Parameters
from the contextual menu.
The Change Method Parameters dialog box
opens.
- Click the Add button to add a parameter.
- In the Parameters table, modify the name and type of the parameter that you have
added. Then add a default value for the parameter in the Value column.
You need to double-click a cell to make it editable.
- If you click Refactor, the IDE applies
the changes automatically and skips the remaining steps. If you click Preview,
the Refactoring window displays the lines of code that will be changed. Review
the list and clear the checkbox of any code that you do not want changed. If the
class that you are pushing members from has multiple subclasses and you do not
want the members to be pushed to all of them, be sure to clear the checkboxes
for the corresponding subclasses. Click Do Refactoring to apply the selected changes.
To reorder a parameter in a method signature:
- Right-click the method in the Source Editor and choose
Refactor > Change Method Parameters
from the contextual menu.
- Select a parameter that you want to move and click Move Up or Move Down to change its
position in the list.
- Click Next. If you click Refactor, the IDE applies
the changes automatically and skips the remaining steps.
- The Refactoring window displays the lines of code that will be changed. Review
the list and clear the checkbox of any code that you do not want changed.
- Click Do Refactoring to apply the selected changes.
To change a method's access modifier:
- Right-click the method in the Source Editor and choose
Refactor > Change Method Parameters
from the contextual menu.
- Choose a modifier from the Visibility Modifier combo box.
- If you click Refactor, the IDE applies
the changes automatically and skips the remaining steps. If you click Preview,
the Refactoring window displays the lines of code that will be changed. Review
the list and clear the checkbox of any code that you do not want changed. If the
class that you are pushing members from has multiple subclasses and you do not
want the members to be pushed to all of them, be sure to clear the checkboxes
for the corresponding subclasses. Click Do Refactoring to apply the selected changes.
- See Also
- Refactoring: Quick Reference
- Moving a Class Member to a Superclass
- Moving a Class Member to a Subclass
- Extracting a Method
- Renaming a Field or Method
- Undoing Refactoring Changes
Legal Notices