code: private static <T> T cast(Class<T> clazz, Object o) {
          if (! clazz.isInstance(o))
              throw new IllegalArgumentException(o.toString());
          return clazz.cast(o);
      }
docs: Returns an object cast to the specified type.
  @throws NullPointerException if the object is {@code null}
  @throws IllegalArgumentException if the object is of the wrong type