Here you can find the source of valueOf(final Class> type, final String value)
Parameter | Description |
---|---|
type | the boxed primitive type |
value | the string value |
public static Object valueOf(final Class<?> type, final String value)
//package com.java2s; public class Main { /**/* w w w. j av a2 s .c om*/ * Convert a string value to a boxed primitive type. * * @param type the boxed primitive type * @param value the string value * @return a boxed primitive type */ public static Object valueOf(final Class<?> type, final String value) { if (type == String.class) { return value; } if (type == boolean.class) { return Boolean.valueOf(value); } if (type == int.class) { return Integer.valueOf(value); } if (type == long.class) { return Long.valueOf(value); } if (type == float.class) { return Float.valueOf(value); } if (type == double.class) { return Double.valueOf(value); } throw new IllegalArgumentException("Unsupported type " + type.getName()); } }