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
482684
private static <T> T cast(Class<T> clazz, Object o) {
        if (! clazz.isInstance(o))
            throw new IllegalArgumentException(o.toString());
        return clazz.cast(o);
    }
133547
Object convertArgument(String arg, Type paramType) throws IllegalArgumentException {
		Object result = null;
		if (null == arg || "null".equals(arg)) {
			return result;
		}
		logger.debug("Try to convert {} : param = {} : {}", new Object[]{arg, paramType, paramType.getClass()});
		try { // GenericArrayType, ParameterizedType, TypeVariable<D>, WildcardType, Class
			if (ParameterizedType.class.isInstance(paramType)) {
				JavaType javaType = getJavaType(paramType);
				logger.debug("Try to convert '{}' to JavaType : '{}'", arg, paramType);
				result = getObjectMapper().readValue(arg, javaType);
				logger.debug("Conversion of '{}' to '{}' : OK", arg, paramType);
			} else if (Class.class.isInstance(paramType)) {
				Class cls = (Class) paramType;
				logger.debug("Try to convert '{}' to Class '{}'", arg, paramType);
				checkStringArgument(cls, arg);
				result = getObjectMapper().readValue(arg, cls);
				logger.debug("Conversion of '{}' to '{}' : OK", arg, paramType);
			} else { // GenericArrayType, TypeVariable<D>, WildcardType
				logger.warn("Conversion of '{}' to '{}' not yet supported", arg, paramType);
			}
		} catch (IOException ex) {
			logger.debug("Conversion of '{}' to '{}' failed", arg, paramType);
			throw new IllegalArgumentException(paramType.toString());
		}
		return result;
	}
512331
private <T> T get(Class<T> clazz) {
    try {
      return clazz.cast(get());
    } catch (ClassCastException e) {
      return null;
    }
  }
591540
@Pure
	@SuppressWarnings("unchecked")
	public Class<? extends T> getValueType() {
		if (this.object == null) {
			return null;
		}
		return (Class<? extends T>) this.object.getClass();
	}
1273522
public static ExceptionThrower instance(Class<? extends RuntimeException> classType) {

        iae.throwIfNull(classType, "The parameter of exception type can not be null.");
        if (classType.equals(IllegalArgumentException.class)) {
            return iae;
        } else {
            iae.throwIfTrue(true, "Not fond ExceptionThrower Utils for :", classType.getClass()
                    .toString());
            return null;
        }
    }
247263
public Object castToType(int t, XPathContext support)
          throws javax.xml.transform.TransformerException
  {

    Object result;

    switch (t)
    {
    case CLASS_STRING :
      result = str();
      break;
    case CLASS_NUMBER :
      result = new Double(num());
      break;
    case CLASS_NODESET :
      result = iter();
      break;
    case CLASS_BOOLEAN :
      result = new Boolean(bool());
      break;
    case CLASS_UNKNOWN :
      result = m_obj;
      break;

    // %TBD%  What to do here?
    //    case CLASS_RTREEFRAG :
    //      result = rtree(support);
    //      break;
    default :
      error(XPATHErrorResources.ER_CANT_CONVERT_TO_TYPE,
            new Object[]{ getTypeString(),
                          Integer.toString(t) });  //"Can not convert "+getTypeString()+" to a type#"+t);

      result = null;
    }

    return result;
  }
892030
@Override
    <T> Class<T> loadClass(final Class<T> superclassOrInterfaceType) {
        final Class<?> type = getType();
        if (!superclassOrInterfaceType.isAssignableFrom(type)) {
            throw new IllegalArgumentException(
                    "Primitive class " + baseType + " cannot be cast to " + superclassOrInterfaceType.getName());
        }
        @SuppressWarnings("unchecked")
        final Class<T> classT = (Class<T>) type;
        return classT;
    }
828687
public static Object castNumberType(Object object, Class clazz) {

        if (Number.class.isAssignableFrom(clazz)) {
            //            AtomicInteger, AtomicLong, BigDecimal, BigInteger, Byte, Double, Float, Integer, Long, Short
            if (Double.class.isAssignableFrom(clazz)) {
                return ((Number) object).doubleValue();
            } else if (Long.class.isAssignableFrom(clazz)) {
                return ((Number) object).longValue();

            } else if (Float.class.isAssignableFrom(clazz)) {
                return ((Number) object).floatValue();

            } else if (Integer.class.isAssignableFrom(clazz)) {
                return ((Number) object).intValue();

            } else if (Short.class.isAssignableFrom(clazz)) {
                return ((Number) object).shortValue();

            } else if (Byte.class.isAssignableFrom(clazz)) {
                return ((Number) object).byteValue();

            } else if (BigInteger.class.isAssignableFrom(clazz)) {
                return BigInteger.valueOf(((Number) object).longValue());

            } else if (BigDecimal.class.isAssignableFrom(clazz)) {
                return BigDecimal.valueOf(((Number) object).longValue());

            } else if (AtomicLong.class.isAssignableFrom(clazz)) {
                return new AtomicLong(((Number) object).longValue());

            } else if (AtomicInteger.class.isAssignableFrom(clazz)) {
                return new AtomicInteger(((Number) object).intValue());
            }
        }
        throw new ClassCastException("it is not a Number Type" + object.getClass() + "|" + clazz);
    }
473070
public <T> T get(Class<T> stateType) {
		Map<Class<?>, Object> states = getStates();
		T value = getState( states, stateType );

		if ( value == null ) {
			throw new IllegalArgumentException( "Accessing state of type not enabled: " + stateType );
		}

		return value;
	}
270911
@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;
    }
913946
public static <T> T cast(Object value, Class<T> type) {
        if (null == value) {
            return null;
        }
        if (!type.isAssignableFrom(value.getClass())) {
            if (is(type, int.class, Integer.class)) {
                value = Integer.parseInt(value.toString());
            } else if (is(type, long.class, Long.class)) {
                value = Long.parseLong(value.toString());
            } else if (is(type, float.class, Float.class)) {
                value = Float.parseFloat(value.toString());
            } else if (is(type, double.class, Double.class)) {
                value = Double.parseDouble(value.toString());
            } else if (is(type, boolean.class, Boolean.class)) {
                value = Boolean.parseBoolean(value.toString());
            } else if (is(type, String.class)) {
                value = value.toString();
            }
        }
        return (T) value;
    }
1089501
public function cast($javaObject, string $cast_type)
    {
        /* @todo see how can it be possible to clean up to new structure
            const CAST_TYPE_STRING  = 'string';
            const CAST_TYPE_BOOLEAN = 'boolean';
            const CAST_TYPE_INTEGER = 'integer';
            const CAST_TYPE_FLOAT   = 'float';
            const CAST_TYPE_ARRAY   = 'array';
            const CAST_TYPE_NULL    = 'null';
            const CAST_TYPE_OBJECT  = 'object';
            const CAST_TYPE_NULL -> null
         */
        $first_char = strtoupper(substr($cast_type, 0, 1));
        switch ($first_char) {
            case 'S':
                return (string) $javaObject;
            case 'B':
                return (bool) $javaObject;
            case 'L':
            case 'I':
                return (int) $javaObject;
            case 'D':
            case 'F':
                return (float) $javaObject;
            case 'N':
                return null;
            case 'A':
                return (array) $javaObject;
            case 'O':
                return (object) $javaObject;
            default:
                throw new Exception\RuntimeException("Unsupported cast_type parameter: $cast_type");
        }
    }
744675
public static <T> T castSafely(@Nullable Object o, @NotNull Class<T> type) {
    checkNotNull(type);
    if (type.isPrimitive()) {
      return getWrapperType(type).cast(o);
    }
    return type.cast(o);
  }
677023
def get_nullable_type(type_):  # noqa: F811
    """"""
    if is_non_null_type(type_):
        type_ = cast(GraphQLNonNull, type_)
        type_ = type_.of_type
    return cast(Optional[GraphQLNullableType], type_)
1187873
public static Class<?> typeToClass(Type t) {
		if (t instanceof Class) {
			return (Class<?>)t;
		}
		else if (t instanceof ParameterizedType) {
			return ((Class<?>) ((ParameterizedType) t).getRawType());
		}
		throw new IllegalArgumentException("Cannot convert type to class");
	}
353069
def cast(self, value, custom_formatters=None, strict=True):
        """"""
        if value is None:
            if not self.nullable:
                raise InvalidSchemaValue("Null value for non-nullable schema", value, self.type)
            return self.default

        cast_mapping = self.get_cast_mapping(
            custom_formatters=custom_formatters, strict=strict)

        if self.type is not SchemaType.STRING and value == '':
            return None

        cast_callable = cast_mapping[self.type]
        try:
            return cast_callable(value)
        except ValueError:
            raise InvalidSchemaValue(
                "Failed to cast value {value} to type {type}", value, self.type)
775565
public Class<?> getJavaType() {
		if(javaType==null) {
			javaType=JKTypeMapping.getType(getCode()).getClass();
			if(javaType==null) {
				JK.error("JKType cannot by null, and code not avaiable %s",code);
			}
		}
		return javaType;
	}