Interface Converter<S,​T>

    • Method Detail

      • accept

        default boolean accept​(java.lang.Class<?> sourceType,
                               java.lang.Class<?> targetType)
        Accept the source type and target type or not
        Parameters:
        sourceType - the source type
        targetType - the target type
        Returns:
        if accepted, return true, or false
      • convert

        @Nullable
        T convert​(@Nullable
                  S source)
        Convert the source-typed value to the target-typed value
        Parameters:
        source - the source-typed value
        Returns:
        the target-typed value
      • getSourceType

        default java.lang.Class<S> getSourceType()
        Get the source type
        Returns:
        non-null
      • getTargetType

        default java.lang.Class<T> getTargetType()
        Get the target type
        Returns:
        non-null
      • getConverter

        static <S,​T> Converter<S,​T> getConverter​(java.lang.Class<S> sourceType,
                                                             java.lang.Class<T> targetType)
        Get the Converter instance from ServiceLoader with the specified source and target type
        Parameters:
        sourceType - the source type
        targetType - the target type
        Returns:
      • 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
        Type Parameters:
        T - the target type
        Parameters:
        source - the value of source
        targetType - the target type
        Returns:
        null if can't be converted