Compiler Error J0097

'instanceof' operator expected class or array

The compiler detected the instanceof operator applied to a type that did not resolve to a class or array. The instanceof operator is used to determine if identifier is an instance of a specific class or array. Ensure the lvalue used with the instanceof operator references a class instance or array and the rvalue references a valid class name or array and compile again.

The following example illustrates this error:

public class Simple {
   
   public void method1() {
   
      Simple2 obj = new Simple2();
   
      if (obj instanceof int) // error: 'int' is not a class name
          // do something meaningful
   }
}

class Simple2 {
   // do something meaningful
}