泛型T
程序员文章站
2022-03-13 12:09:11
...
/**
* 将任意类型转换成字符串
* @param value
* @param <T>
* @return
*/
public static <T> String beanToString(T value) {
Class<?> clazz = value.getClass();
if (clazz == int.class || clazz == Integer.class) {
return value + "";
} else if (clazz == String.class) {
return (String) value;
} else if (clazz == long.class || clazz == Long.class) {
return value + "";
} else {
return JSON.toJSONString(value);
}
}