# 类型迁移

> For the complete documentation index, see [llms.txt](https://www.jetbrains.com.cn/help/idea/llms.txt).

> **TL;DR**
> `重构 | 类型迁移`
>
>
>
> `Ctrl+Shift+F6` (Windows), `⌘ ⇧ F6` (macOS), `⌘ ⇧ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F6` (macOS System Shortcuts), `Ctrl+Shift+F6` (XWin), `Ctrl+Shift+F6` (GNOME), `Ctrl+Shift+F6` (KDE), `Ctrl+Shift+F6` (Emacs), `Ctrl+Shift+F6` (Sublime Text), `Ctrl+Shift+F6` (Sublime Text (macOS)), `Ctrl+Shift+F6` (Visual Studio), `⌘ ⇧ F6` (Visual Studio (macOS)), `Ctrl+Shift+F6` (NetBeans), `Ctrl+Shift+F6` (Eclipse), `Ctrl+Shift+F6` (Eclipse (macOS))

类型迁移重构允许您自动更改成员类型（例如从 integer 到 string），以及整个项目中数据流依赖的类型条目（例如方法返回类型、局部变量、参数等）。

它还允许您在数组和集合之间自动转换变量或方法返回类型。 如果发现任何冲突，IntelliJ IDEA 将显示相应的消息。

> **Tip:**
> 这种重构也可以从 [UML 类图](class-diagram.html) 中完成。

Procedure:

1. 在编辑器中，高亮显示或将文本光标放置在您要重构的类型上。

2. 请按 `Ctrl+Shift+F6` (Windows), `⌘ ⇧ F6` (macOS), `⌘ ⇧ F6` (IntelliJ IDEA Classic (macOS)), `⌘ ⇧ F6` (macOS System Shortcuts), `Ctrl+Shift+F6` (XWin), `Ctrl+Shift+F6` (GNOME), `Ctrl+Shift+F6` (KDE), `Ctrl+Shift+F6` (Emacs), `Ctrl+Shift+F6` (Sublime Text), `Ctrl+Shift+F6` (Sublime Text (macOS)), `Ctrl+Shift+F6` (Visual Studio), `⌘ ⇧ F6` (Visual Studio (macOS)), `Ctrl+Shift+F6` (NetBeans), `Ctrl+Shift+F6` (Eclipse), `Ctrl+Shift+F6` (Eclipse (macOS)) 或在主菜单中，进入  `重构 | 类型迁移` 。

3. 在打开的对话框中，指定新类型和要查找用法的范围。

4. [预览并应用更改](refactoring-source-code.html#changes_preview).

## 示例

`f: int -> String`

|  之前  |  之后  |
| --- | --- |
|     ```JAVA int f; void bar(int i) {} void foo() {     bar(f); }  ```    |     ```JAVA String f; void bar(String i) {} void foo() {     bar(f); }  ```    |

`I<String> -> I<Integer>`

|  之前  |  之后  |
| --- | --- |
|     ```JAVA 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;     } }   ```    |     ```JAVA 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[]`

|  之前  |  之后  |
| --- | --- |
|     ```JAVA public class ResultContainer {     private ArrayList<String> myResult;     public String[] getResult() {         return myResult.toArray(new String[myResult.size()]);     } }  ```    |     ```JAVA public class ResultContainer {     private String[] myResult;     public String[] getResult() {         return myResult;     } }  ```    |

## 类型迁移对话框

当您调用 [Type Migration](#to_type_migrate)重构时，将出现此对话框。

|  条目  |  描述  |
| --- | --- |
|  迁移类型  |  使用此列表来指定新类型。  |
|  选择范围  |  使用此列表指定迁移范围。 如果需要，请点击   浏览   ![浏览按钮](https://resources.jetbrains.com.cn/help/img/idea/2026.3/app.general.ellipsis.svg)。  |
|  重构  |  点击此按钮以在指定范围内启动针对所有用法的重构。 如果有任何冲突，IntelliJ IDEA 会通知您。  |
|  预览  |  点击此按钮以浏览需更改的项目，将其排除或包含在重构中，并查看检测到的冲突。  |

## See also

### 重构

[代码重构](refactoring-source-code.html)

