ConversionService接口用法
接口简介
用于类型转换的服务接口。这是进入转换系统的入口点。在此系统调用convert(Object, Class)
来执行线程安全的类型转换
方法简介
boolean canConvert(Class<?> sourceType, Class<?> targetType);
如果sourceType
可以转换成targetType
则返回true
。如果此方法返回true,其表示convert
方法有能力把一个实例从sourceType
转换成targetType
。
特别注意集合,数组,映射类型,即使一个转换调用仍产生一个ConversionException
如果下面的类型不能被转换,此方法仍返回true
。调用者被期待处理这样的异常情况当与集和映射一起工作时。
boolean canConvert(TypeDescriptor sourceType, TypeDescriptor targetType);
<T> T convert(Object source, Class<?> targetType)
把指定的source转换成指定的类型