Here you can find the source of invokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue)
public static void invokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue) throws Exception
//package com.java2s; //License from project: Apache License import java.lang.reflect.Method; public class Main { public static void invokePrimivite(Object entity, Method writeMethod, Class propertyType, String propertyValue) throws Exception { if (isByte(propertyType)) { writeMethod.invoke(entity, Byte.parseByte(propertyValue)); } else if (isShort(propertyType)) { writeMethod.invoke(entity, Short.parseShort(propertyValue)); } else if (isInt(propertyType)) { writeMethod.invoke(entity, Integer.parseInt(propertyValue)); } else if (isLong(propertyType)) { writeMethod.invoke(entity, Long.parseLong(propertyValue)); } else if (isFloat(propertyType)) { writeMethod.invoke(entity, Float.parseFloat(propertyValue)); } else if (isDouble(propertyType)) { writeMethod.invoke(entity, Double.parseDouble(propertyValue)); } else if (isBoolean(propertyType)) { writeMethod.invoke(entity, Boolean.parseBoolean(propertyValue)); } else if (isChar(propertyType)) { writeMethod.invoke(entity, propertyValue.charAt(0)); }/*from w ww.ja va 2s .c o m*/ } public static boolean isByte(Class clazz) { return (clazz == Byte.class) || (clazz == byte.class); } public static boolean isShort(Class clazz) { return (clazz == Short.class) || (clazz == short.class); } public static boolean isInt(Class clazz) { return (clazz == Integer.class) || (clazz == int.class); } public static boolean isLong(Class clazz) { return (clazz == Long.class) || (clazz == long.class); } public static boolean isFloat(Class clazz) { return (clazz == Float.class) || (clazz == float.class); } public static boolean isDouble(Class clazz) { return (clazz == Double.class) || (clazz == double.class); } public static boolean isBoolean(Class clazz) { return (clazz == Boolean.class) || (clazz == boolean.class); } public static boolean isChar(Class clazz) { return (clazz == Character.class) || (clazz == char.class); } }