Compiler Warning J5016

This 'instanceof' operator will always be true

The compiler determined that the specified instanceof expression will always evaluate to true. This can occur when instanceof is used to determine if a subclass instance is a member of a base class or an implemented interface. Although it is not an error to use the instanceof operator in this fashion, it's not particularly useful since the expression will always evaluate to true.

The following example illustrates this warning:

interface I {}
class X {}
class Y extends X implements I {}

public class Simple{
   void f()
   {
      Y y = new Y();
      X x = new X();
      Object o;

      // These statements give J5016 warnings...
      if (y instanceof X){
         // y is of type Y, which extends X, so this is always true
      }
      if (y instanceof I){
         // type Y implements I, so this is always true.
      }
      if (x instanceof Object){
         // everything is of type Object
      }
   }
}