Java Object Type Case castObject(Object fromObj, Class toClass)

Here you can find the source of castObject(Object fromObj, Class toClass)

Description

castObject returns boolean value indicating whether the value need to be cast

License

Open Source License

Parameter

Parameter Description
value a parameter
toClass - class to be cast to

Return

boolean

Declaration

private static boolean castObject(Object fromObj, Class<?> toClass) 

Method Source Code

//package com.java2s;

public class Main {
    /**castObject/*from w  ww  .  ja v a  2 s  .  co m*/
     * returns boolean value indicating whether the value need to be cast
     * @param value
     * @param toClass - class to be cast to
     * @return boolean
     */
    private static boolean castObject(Object fromObj, Class<?> toClass) {
        if (toClass.equals(fromObj.getClass())) {
            return false;
        } else if (toClass.isPrimitive()) {
            if (toClass.equals(long.class) && fromObj.getClass().equals(Long.class)) {
                return false;
            } else if (toClass.equals(int.class) && fromObj.getClass().equals(Integer.class)) {
                return false;
            } else if (toClass.equals(double.class) && fromObj.getClass().equals(Double.class)) {
                return false;
            }
        }
        return true;
    }
}

Related

  1. castNode(Class jsonNode, Class classz)
  2. castNonNullArray( T [] arr)
  3. castNullableParameterTo(String parameterName, T value, Class requiredType)
  4. castNumber(Number num, Class clazz)
  5. castObject(Class clazz, Object object)
  6. castObject(Object ob)
  7. castOrDefault(Class type, Object value, T defaultValue, boolean allowNull)
  8. castOrDefault(Object o, Class type, T def)
  9. castOrNull(Object o, Class clazz)