code: protected static <T> T checkType(String view, String attribute, Object value, Class<T> type) {
      checkNotNull(value);
      if (type.isInstance(value)) {
        return type.cast(value);
      }
  
      throw invalidType(view, attribute, value, type);
    }
docs: Checks that the given value is of the given type, returning the value if so and throwing an
  exception if not.