Java Utililty Methods Object Type Case

List of utility methods to do Object Type Case

Description

The list of methods to do Object Type Case are organized into topic(s).

Method

Acast(Object object, Class targetClass)
cast
return targetClass.cast(object);
Tcast(Object source)
cast
try {
    return source == null ? null : (T) source;
} catch (Exception e) {
    throw new IllegalArgumentException("Cannot convert to type");
Objectcast(Object val, Class type)
cast
if (val == null)
    return null;
if (type == Boolean.class || type == Boolean.TYPE) {
    return ((Boolean) val).booleanValue();
} else if (type == Character.class || type == Character.TYPE) {
    return ((Character) val).charValue();
} else if (type == Byte.class || type == Byte.TYPE) {
    return ((Byte) val).byteValue();
...
Stringcast(Object value, String sqlType)
cast
return "cast(" + value + " as " + sqlType + ")";
Tcast(Object x)
Use this function to eliminate silly "unchecked" warnings that cannot be fixed in Java otherwise.
return (T) x;
Tcast(Object x)
cast
return (T) x;
Object[]cast(Object[] parameters, Class[] types)
cast
for (int i = 0; i < parameters.length; i++) {
    parameters[i] = types[i].cast(parameters[i]);
return parameters;
Stringcast(String type)
cast
if (type == null) {
    return type;
if (type.equals(Object.class.getName())) {
    return ""; 
return "(" + type + ")"; 
voidcastAndThrow(Throwable e)
cast And Throw
throw (T) e;
T[]castArray(Object[] array, T[] targetArray)
cast Array
for (int i = 0; i < array.length; i++) {
    targetArray[i] = (T) array[i];
return targetArray;