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:

  1. 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.

  2. Click the Add button to add a parameter.
  3. 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.
  4. (Optional) If you do not want to review the changes before they are made, clear the Preview All Changes checkbox.
  5. (Optional) Choose a modifier from the Visibility Modifier combo to change the access modifier.
  6. Click Next. If you have cleared the Preview All Changes checkbox, the IDE applies the changes automatically and skips the remaining steps.
  7. 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.
  8. (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.
  9. Click Do Refactoring to apply the selected changes.

To reorder a parameter in a method signature:

  1. Right-click the method in the Source Editor and choose Refactor > Change Method Parameters from the contextual menu.
  2. Select a parameter that you want to move and click Move Up or Move Down to change its position in the list.
  3. Click Next. If you have cleared the Preview All Changes checkbox, the IDE applies the changes automatically and skips the remaining steps.
  4. 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.
  5. Click Do Refactoring to apply the selected changes.

To change a method's access modifier:

  1. Right-click the method in the Source Editor and choose Refactor > Change Method Parameters from the contextual menu.
  2. Choose a modifier from the Visibility Modifier combo box.
  3. (Optional) If you do not want to review the changes before they are made, clear the Preview All Changes checkbox.
  4. Click Next. If you have cleared the Preview All Changes checkbox, the IDE applies the changes automatically and skips the remaining steps.
  5. 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.
  6. (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.
  7. 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