IntelliJ IDEA 2022.2 Help

Type migration

The Type Migration refactoring lets you automatically change a member type (e.g. from integer to string), and data flow dependent type entries, like method return types, local variables, parameters etc. across the entire project.

It also lets you automatically convert variable or method return type between arrays and collections. If any conflicts are found IntelliJ IDEA displays the appropriate message.

  1. In the editor, highlight or place the caret at a type you want to refactor.

  2. Press Ctrl+Shift+F6 or on the main menu, select Refactor | Type Migration.

  3. In the dialog that opens, specify the new type and scope where to look for the usages.

  4. Preview and apply the changes.

Examples

f: int -> String

Before

After

int f; void bar(int i) {} void foo() { bar(f); }
String f; void bar(String i) {} void foo() { bar(f); }

I<String> -> I<Integer>

Before

After

interface I<T> { T foo(T t); } class A implements I<String> { String myString; public String foo(final String s) { if (s == null) { return myString; } return s; } }
interface I<T> { T foo(T t); } class A implements I<Integer> { Integer myString; public Integer foo(final Integer s) { if (s == null) { return myString; } return s; } }

myResult: ArrayList<String> -> String[]

Before

After

public class ResultContainer { private ArrayList<String> myResult; public String[] getResult() { return myResult.toArray(new String[myResult.size()]); } }
public class ResultContainer { private String[] myResult; public String[] getResult() { return myResult; } }
Last modified: 29 November 2022