code: public static Object convert(String str, Class<?> type) throws Exception {
          Object value;
          if (int.class.equals(type) || Integer.class.equals(type))
              value = Integer.parseInt(str);
          else if (boolean.class.equals(type) || Boolean.class.equals(type))
              value = Boolean.parseBoolean(str);
          else if (long.class.equals(type) || Long.class.equals(type))
              value = Long.parseLong(str);
          else if (short.class.equals(type) || Short.class.equals(type))
              value = Short.parseShort(str);
          else if (byte.class.equals(type) || Byte.class.equals(type))
              value = Byte.parseByte(str);
          else if (double.class.equals(type) || Double.class.equals(type))
              value = Double.parseDouble(str);
          else if (float.class.equals(type) || Float.class.equals(type))
              value = Float.parseFloat(str);
          else if (char.class.equals(type) || Character.class.equals(type))
              value = str.charAt(0);
          else
              value = type.getConstructor(String.class).newInstance(str);
          return value;
      }
docs: Converts a String value to the specified type.
  
  @param str a String value.
  @param type the desired type, which can be a primitive or primitive wrapper.
  @return converted value.