Interface TypeConverter
public interface TypeConverter
Type Converter SPI
类型转换器SPI
Provides a service provider interface for type conversion.
为类型转换提供服务提供者接口。
Features | 主要功能:
- SPI for custom type conversion logic - 用于自定义类型转换逻辑的SPI
- Convertibility check before conversion - 转换前的可转换性检查
- Generic type-safe conversion method - 泛型类型安全转换方法
Usage Examples | 使用示例:
public class MoneyTypeConverter implements TypeConverter {
@Override
public boolean canConvert(Class<?> source, Class<?> target) {
return target == Money.class && source == String.class;
}
@Override
public <T> T convert(Object value, Class<T> targetType) {
return targetType.cast(Money.parse((String) value));
}
}
Security | 安全性:
- Thread-safe: Depends on implementation - 线程安全: 取决于实现
- Null-safe: Depends on implementation - 空值安全: 取决于实现
Performance | 性能特性:
- Time complexity: O(1) for canConvert and convert in typical implementations - 时间复杂度: 典型实现中 canConvert 和 convert 均为 O(1)
- Space complexity: O(1) - 空间复杂度: O(1)
- Since:
- JDK 25, opencode-base-expression V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
-
Method Details
-
canConvert
-
convert
-