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.
- (Optional) If you do not want to review the changes before they are made,
clear the Preview All Changes checkbox.
- (Optional) Choose a modifier from the Visibility Modifier combo
to change the access modifier.
- Click Next. If you have cleared the Preview All Changes checkbox, 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.
- (Optional) Double-click a file name in the Refactoring window to open the file,
or double-click a line of code to open the file and to put the insertion
point in that line of code.
- 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 have cleared the Preview All Changes checkbox, 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.
- (Optional) If you do not want to review the changes before they are made,
clear the Preview All Changes checkbox.
- Click Next. If you have cleared the Preview All Changes checkbox, 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.
- (Optional) Double-click a file name in the Refactoring window to open the file,
or double-click a line of code to open the file and to put the insertion
point in that line of code.
- 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