IntelliJ IDEA 2017.2 Help

Keymap:

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

Before

After

// This is the class whose signature will be changed:publicclassMyClass{// some code here}publicclassMyOtherClass{// Here are the references to MyClass:MyClassmyClass;voidmyMethod(MyClassmyClass){// some code here}// some code here}// Now we are going to add two formal type parameters// to MyClass.

// Two formal type parameters have been added:publicclassMyClass<Param1,Param2>{// some code here}publicclassMyOtherClass{// The references to MyClass have changed accordingly:MyClass<String,Integer>myClass;voidmyMethod(MyClass<String,Integer>myClass){// some code here}// some code here}// When performing the refactoring, String and Integer// were specified as the default values for Param1 and// Param2 respectively.

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 to public class ClassA<T, E extends T>. However, if the parameter order was initially public 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.