Here you can find the source of convertString(String s, Class> cls)
Parameter | Description |
---|---|
s | a string |
cls | the type to convert the string to |
public static Object convertString(String s, Class<?> cls)
//package com.java2s; //License from project: Open Source License public class Main { /**//w ww .j av a2s . c o m * Convert a string into an object of given type. * * @param s a string * @param cls the type to convert the string to * @return object of given type */ public static Object convertString(String s, Class<?> cls) { if (cls == Integer.class) { return Integer.valueOf(s); } else if (cls == String.class) { return s; } else { throw new IllegalArgumentException("Don't know how to convert string to " + cls.getName()); } } }