匿名クラスを内部クラスに置換すると、コードの可読性とメンテナンス性が向上する場合があります。 一部のコード標準は匿名クラスを推奨していません。
例:
class Example {
public static void main(String[] args) {
new Thread() {
public void run() {
work()
}
private void work() {}
}.start();
}
}
クイックフィックス適用後:
class Example {
public static void main(String[] args) {
new MyThread().start();
}
private static class MyThread extends Thread {
public void run() {
work();
}
private void work() {}
}
}