List of utility methods to do Object Type Case
T | cast(Class cast if (value == null) { return null; if (!type.isAssignableFrom(value.getClass())) { throw new Exception("Value has invalid type" + (key == null ? "" : " for key: " + key) + " -- expected '" + type.getName() + "', got: " + value.getClass().getName()); return (T) value; ... |
T | cast(Class Cast an object type to the specified type. return (type.isInstance(obj)) ? type.cast(obj) : null;
|
int[] | cast(double[] arr) cast double[] to int[] int[] carr = new int[arr.length]; for (int i = 0; i < arr.length; i++) { carr[i] = (int) arr[i]; return carr; |
Class | cast(final Class> clazz) Casts a class to a required type return (Class<T>) clazz;
|
R | cast(final Number number, final Class Casts the number to the provided return type. if ((number == null) || (returnType == null)) { return null; if (returnType == Double.class) { final Double value = number.doubleValue(); return returnType.cast(value); } else if (returnType == Float.class) { final Float value = number.floatValue(); ... |
T | cast(final Object o) Utility method to perform generic casts without dealing with Unchecked cast warnings (or having to apply SuppressWarnings("unchecked") annotations).
return (T) o;
|
T | cast(final Object obj, final Class Casts the given object to the specified type, or null if the types are incompatible. if (!canCast(obj, type)) return null; @SuppressWarnings("unchecked") final T result = (T) obj; return result; |
T | cast(final Object object) Auto cast an object. return (T) object;
|
T | cast(final Object original) Casting in the way that it is not a problem for findbugs yet it can throw a classcast exception. @SuppressWarnings("unchecked") T result = (T) original; return result; |
short | cast(int value) cast return value > Short.MAX_VALUE ? Short.MAX_VALUE : value < Short.MIN_VALUE ? Short.MIN_VALUE : (short) value; |