Change Class Signature
The Change Class Signature refactoring lets you turn a class into a generic and manipulate its type parameters. The refactoring automatically corrects all calls, implementations and overridings of the class.
Example
Use cases
-
The type parameters can have bounds extending other constructs including other type parameters from
another class.
For instance, the code like
public class ClassA<T, E>
can be easily transformed topublic class ClassA<T, E extends T>
. However, if the parameter order was initiallypublic class ClassA<E, T>
, the Change Class Signature refactoring may be useful for changing the parameter order in the class signature as well as in all its usages. - IntelliJ IDEA can successfully deal with rather complicated cases and can alter parameters and corresponding usages if one parameter depends on another.
Changing a class signature
To change a class signature, follow these steps
- In the editor, place the cursor within the name of the class whose signature you want to change.
- Do one of the following:
- In the Change Class Signature dialog, use the available
controls to manage the formal type parameters:
- To add a new parameter, click
or press Alt+Insert. Specify the parameter name and default type in the Name and the Default Value fields respectively.
- To remove a parameter, select the parameter and
click
(Alt+Delete).
- To move a parameter up or down in the list, select the parameter and then
use
(Alt+Up) or
(Alt+Down).
- To add a new parameter, click
- To perform the refactoring right away, click Refactor.
To see the expected changes and make the necessary adjustments prior to actually performing the refactoring, click Preview.
See Also
Reference:
Last modified: 13 July 2016