Java tutorial
//package com.java2s; public class Main { private static Object convertValType(Object value, Class<?> fieldTypeClass) { Object retVal; if (Long.class == fieldTypeClass || long.class == fieldTypeClass) { retVal = Long.parseLong(value.toString()); } else if (Integer.class == fieldTypeClass || int.class == fieldTypeClass) { retVal = Integer.parseInt(value.toString()); } else if (Float.class == fieldTypeClass || float.class == fieldTypeClass) { retVal = Float.parseFloat(value.toString()); } else if (Double.class == fieldTypeClass || double.class == fieldTypeClass) { retVal = Double.parseDouble(value.toString()); } else { retVal = value; } return retVal; } }