Here you can find the source of castObject(Object fromObj, Class> toClass)
Parameter | Description |
---|---|
value | a parameter |
toClass | - class to be cast to |
private static boolean castObject(Object fromObj, Class<?> toClass)
//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; } }