在 Intellij 中,如何安全地重构循环中的 continue 语句?

Dan*_*lan 3 java refactoring intellij-idea

我讨厌java 代码中的continues (和breaks),但我并不总是编写代码的人,所以我想知道 Intellij 是否有一种安全的方法将它们从循环中删除?下面是一个简单的示例,显示了打印奇数的 for 循环:

package com.sandbox;

import static java.util.Arrays.asList;

public class Sandbox {

    public static void main(String[] args) {
        new Sandbox().run();
    }

    private void run() {
        for (Integer integer : asList(1, 2, 3, 4, 5, 6, 7)) {
            if (integer % 2 == 0) {
                continue;
            }
            System.out.println(integer);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

如何摆脱这个问题continue而不用担心我是否破坏了代码?

Pet*_*mov 5

Alt+Enter 在 if 条件上并选择“反转 If 条件”。它删除了您的示例和其他示例中的“继续”。