- Opening the Source Editor
- Managing Automatic Insertion of Closing Characters
- Displaying Line Numbers
- Generating Code Snippets without Leaving the Keyboard
- Using Code Completion
- Inserting Snippets from Code Templates
- Using Editor Hints to Generate Missing Code
- Matching Other Words in a File
- Generating Methods to Implement and Override
- Generating JavaBeans Component Code
- Creating and Using Macros
- Creating and Customizing File Templates
- Handling Imports
- Displaying Javadoc Documentation While Editing
- Formatting Code
- Text Selection Shortcuts
- Navigating within the Current Java File
- Navigating from the Source Editor
- Searching and Replacing
- Deleting Code Safely
- Changing a Method's Signature
- Encapsulating a Field
- Moving a Class to a Different Package
- Moving Class Members to Other Classes
- Creating a Method from Existing Statements
- Creating an Interface from Existing Methods
- Extracting a Superclass to Consolidate Common Methods
- Changing References to Use a Supertype
- Unnesting Classes
- Tracking Notes to Yourself in Your Code
- Comparing Differences Between Two Files
- Splitting the Source Editor
- Maximizing Space for the Source Editor
- Changing Source Editor Keyboard Shortcuts
Changing References to Use a Supertype
You can use the Use Supertype Where Possible refactoring command to change code to reference objects of a superclass (or other type) instead of objects of a subclass. The operation only changes the reference in places where your code can accommodate such upcasting.
Typically you would use this refactoring operation to enable a single method to take as an argument different types of objects (all deriving from the same superclass).
This operation might be particularly useful after you have used the Extract Superclass command.
To change references to a supertype:
- Select the class to which you want to replaces references and choose Refactor | Use Supertype Where Possible.
In the Select Supertype to Use list, select the class or other type that should be referenced instead of the type currently referenced and click Next.
If you have deselected the Preview All Changes checkbox, the changes are applied immediately.
If you leave the Preview All Changes checkbox selected, the Refactoring window appears with a preview of the changes.
- In the Refactoring window, look at the preview of the code to be changed. If there is a modification that you do not want to be made, deselect the checkbox next to the line for that change.
Click Do Refactoring.
If you later find that the refactoring has had some consequences that you would like to reverse, you can choose Refactor | Undo.