public static Object valueOf(Class<?> type,String value){
  try {
    if (type.equals(String.class))     return value;
    Method m=class2Value.get(type);
    if (m != null)     return m.invoke(null,value);
    if (type.equals(Character.TYPE) || type.equals(Character.class))     return new Character(value.charAt(0));
    Constructor<?> c=type.getConstructor(String.class);
    return c.newInstance(value);
  }
 catch (  NoSuchMethodException e) {
  }
catch (  IllegalAccessException e) {
  }
catch (  InstantiationException e) {
  }
catch (  InvocationTargetException e) {
    if (e.getTargetException() instanceof Error)     throw (Error)(e.getTargetException());
  }
  return null;
}

public static Object valueOf ( Class < ? > type , String value ) { try { if ( type . equals ( String . class ) ) return value ; Method m = class2Value . get ( type ) ; if ( m != null ) return m . invoke ( null , value ) ; if ( type . equals ( Character . TYPE ) || type . equals ( Character . class ) ) return new Character ( value . charAt ( 0 ) ) ; Constructor < ? > c = type . getConstructor ( String . class ) ; return c . newInstance ( value ) ; } catch ( NoSuchMethodException e ) { } catch ( IllegalAccessException e ) { } catch ( InstantiationException e ) { } catch ( InvocationTargetException e ) { if ( e . getTargetException ( ) instanceof Error ) throw ( Error ) ( e . getTargetException ( ) ) ; } return null ; }
convert string value to instance .
