接口 Converter<S,T>
-
- 类型参数:
S
- The source typeT
- The target type
- 所有超级接口:
java.lang.Comparable<Prioritized>
,Prioritized
- 所有已知子接口:
StringConverter<T>
- 所有已知实现类:
MapToPropertiesConverter
,PropertiesToStringConverter
,StringToBooleanConverter
,StringToCharacterConverter
,StringToCharArrayConverter
,StringToClassConverter
,StringToDoubleConverter
,StringToDurationConverter
,StringToFloatConverter
,StringToInputStreamConverter
,StringToIntegerConverter
,StringToLongConverter
,StringToOptionalConverter
,StringToShortConverter
,StringToStringConverter
- 函数接口:
- 这是一个函数接口, 因此可用作 lambda 表达式或方法引用的赋值目标。
@FunctionalInterface public interface Converter<S,T> extends Prioritized
A class to convert the source-typed value to the target-typed value- 从以下版本开始:
- 1.0.0
-
-
字段概要
-
从接口继承的字段 io.microsphere.lang.Prioritized
COMPARATOR, MAX_PRIORITY, MIN_PRIORITY, NORMAL_PRIORITY
-
-
方法概要
所有方法 静态方法 实例方法 抽象方法 默认方法 修饰符和类型 方法 说明 default boolean
accept(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
Accept the source type and target type or notT
convert(S source)
Convert the source-typed value to the target-typed valuestatic <T> T
convertIfPossible(java.lang.Object source, java.lang.Class<T> targetType)
Convert the value of source to target-type value if possiblestatic <S,T>
Converter<S,T>getConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)
Get the Converter instance fromServiceLoader
with the specified source and target typedefault java.lang.Class<S>
getSourceType()
Get the source typedefault java.lang.Class<T>
getTargetType()
Get the target type-
从接口继承的方法 io.microsphere.lang.Prioritized
compareTo, getPriority
-
-
-
-
方法详细资料
-
accept
default boolean accept(java.lang.Class<?> sourceType, java.lang.Class<?> targetType)
Accept the source type and target type or not- 参数:
sourceType
- the source typetargetType
- the target type- 返回:
- if accepted, return
true
, orfalse
-
convert
T convert(S source)
Convert the source-typed value to the target-typed value- 参数:
source
- the source-typed value- 返回:
- the target-typed value
-
getSourceType
default java.lang.Class<S> getSourceType()
Get the source type- 返回:
- non-null
-
getTargetType
default java.lang.Class<T> getTargetType()
Get the target type- 返回:
- non-null
-
getConverter
static <S,T> Converter<S,T> getConverter(java.lang.Class<S> sourceType, java.lang.Class<T> targetType)
Get the Converter instance fromServiceLoader
with the specified source and target type- 参数:
sourceType
- the source typetargetType
- the target type- 返回:
-
convertIfPossible
static <T> T convertIfPossible(java.lang.Object source, java.lang.Class<T> targetType)
Convert the value of source to target-type value if possible- 类型参数:
T
- the target type- 参数:
source
- the value of sourcetargetType
- the target type- 返回:
null
if can't be converted
-
-