@SuppressWarnings("unchecked")
  public static <T> T checkCast(Object castTarget, Class<T> castClass) {
    if (castTarget == null) {
      return null; // null can be cast to anything
    }

    if (!castClass.isInstance(castTarget)) {
      throw new InternalGemFireError(String.format("expected instance of %s but was %s",
          castClass.getName(), castTarget.getClass().getName()));
    }

    return (T) castTarget;
  }
Verify that type-cast will work, or else throw an informative exception.

@return the castTarget
@throws InternalGemFireError if cast will fail
geode-core/src/main/java/org/apache/geode/cache/query/internal/types/TypeUtils.java