code: @SuppressWarnings("unchecked")
      protected <T> T cast(Object arg, Class<T> type) {
          if (arg == null) {
              throw new NullPointerException("Argument is null");
          }
          if (!type.isInstance(arg)) {
              throw FormatException.illegalFormat(getFormatName(), arg.getClass());
          }
          return (T) arg;
      }
docs: Casts a value, and throws a {@link FormatException} if the value has
  the wrong type.
  
  @param <T>
  @param arg
  @param type
  @return arg