instanceof 식이 catch 블록의 매개변수 타입을 테스트하기 위해 사용되는 경우를 보고합니다.

catch 매개변수 타입 테스트는 instanceof를 사용하는 대신에 별도의 catch 블록을 사용하여 수행하는 것이 보통 더 좋습니다.

예:


  void foo(Runnable runnable) {
    try {
        runnable.run();
    } catch (Throwable throwable) {
        if (throwable instanceof NoClassDefFoundError) { // 경고: 'catch' 매개변수 'throwable'의 'instanceof'
            System.out.println("Class not found!");
        }
    }
  }