code: public static <T> T castIfInstance(Object o, Class<T> c) {
          return o != null && c.isInstance(o) ? c.cast(o) : null;
      }
docs: Conditional casting, useful for equals() implementations using instanceof
  
  @param o   The other object
  @param c   The class to check for
  @param <T> The generic type of the target class
  @return The object cast as a T, or null if o is not an instance of c