Converting an Anonymous Inner Class to a Regular Inner Class

See Also

You can use the Convert Anonymous Class to Inner command to convert an anonymous class to an inner class that contains a name and constructor. When you use this operation, a new inner class is created and the anonymous inner class is replaced with a call to the new inner class.

To use the Convert Anonymous Class to Inner operation:

  1. In the Source Editor, place the insertion point in the anonymous inner class that you want to convert.
  2. Choose Refactor > Convert Anonymous Class to Inner.

    The Convert Anonymous Class to Inner dialog box appears.

  3. In the Inner Class Name field, type a name for the inner class to be created.
  4. In the Access field, select the access level that you want for the class.
  5. If you want the class to be static, select the Declare Static checkbox.
  6. (Optional) If the class has multiple constructor parameters, you can use the Move Up or Move Down buttons to change the order of the parameters.
  7. (Optional) If you want to review the changes before they are made, select the Preview All Changes checkbox.
  8. Click Next. If you have not selected the Preview All Changes checkbox, the IDE applies the changes automatically and skips the remaining steps.
  9. If you have selected the Preview All Changes checkbox, 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.
  10. (Optional) Double-click a file name in the Refactoring window to open the file, or double-click a line of code to open the source file and to position the cursor on that line of code.
  11. Click Do Refactoring to apply the selected changes.
See Also
Refactoring: Quick Reference
Moving an Inner Class One Level Up
Moving a Class Member to a Superclass
Moving a Class Member to a Subclass
Moving a Class to Another Java Package
Renaming a Class or Interface
Undoing Refactoring Changes

Legal Notices