Java tutorial
//package com.java2s; import android.util.Log; public class Main { private static final String BYTE = "java.lang.Byte"; private static final String INTEGER = "java.lang.Integer"; private static final String SHORT = "java.lang.Short"; private static final String LONG = "java.lang.Long"; private static final String BOOLEAN = "java.lang.Boolean"; private static final String CHAR = "java.lang.Character"; private static final String FLOAT = "java.lang.Float"; private static final String DOUBLE = "java.lang.Double"; private static final String VALUE_BYTE = "byte"; private static final String VALUE_INTEGER = "int"; private static final String VALUE_SHORT = "short"; private static final String VALUE_LONG = "long"; private static final String VALUE_BOOLEAN = "boolean"; private static final String VALUE_CHAR = "char"; private static final String VALUE_FLOAT = "float"; private static final String VALUE_DOUBLE = "double"; private static Object getValue4Field(Object orginalValue, String typeName) { Log.i("YunMing", typeName); Object value = orginalValue.toString(); if (typeName.equals(BYTE) || typeName.equals(VALUE_BYTE)) { value = Byte.class.cast(orginalValue); } if (typeName.equals(INTEGER) || typeName.equals(VALUE_INTEGER)) { value = Integer.class.cast(orginalValue); } if (typeName.equals(SHORT) || typeName.equals(VALUE_SHORT)) { value = Short.class.cast(orginalValue); } if (typeName.equals(LONG) || typeName.equals(VALUE_LONG)) { value = Long.class.cast(orginalValue); } if (typeName.equals(BOOLEAN) || typeName.equals(VALUE_BOOLEAN)) { value = Boolean.class.cast(orginalValue); } if (typeName.equals(CHAR) || typeName.equals(VALUE_CHAR)) { value = Character.class.cast(orginalValue); } if (typeName.equals(FLOAT) || typeName.equals(VALUE_FLOAT)) { value = Float.class.cast(orginalValue); } if (typeName.equals(DOUBLE) || typeName.equals(VALUE_DOUBLE)) { value = Double.class.cast(orginalValue); } return value; } }