接口 TypeConverter

    • 方法详细资料

      • convertIfNecessary

        @Nullable
        default <T> T convertIfNecessary​(@Nullable
                                         @Nullable Object source,
                                         @NotNull
                                         @NotNull Class<T> requiredType)
                                  throws TypeMismatchException
        将该值转换为所需的类型
        参数:
        source - 要转换的值
        requiredType - 必须转换为的类型
        返回:
        类型转换的结果
        抛出:
        TypeMismatchException - 如果类型转换失败,则抛出该例外
      • convertIfNecessary

        @Nullable
        default <T> T convertIfNecessary​(@Nullable
                                         @Nullable Object source,
                                         @NotNull
                                         @NotNull TypeDescriptor typeDescriptor)
                                  throws TypeMismatchException
        将该值转换为所需的类型
        参数:
        source - 要转换的值
        typeDescriptor - 要使用的类型描述符
        返回:
        类型转换的结果
        抛出:
        TypeMismatchException - 如果类型转换失败,则抛出该例外
      • convertIfNecessary

        @Nullable
        <T> T convertIfNecessary​(@Nullable
                                 @Nullable Object source,
                                 @Nullable
                                 @Nullable Class<T> requiredType,
                                 @Nullable
                                 @Nullable TypeDescriptor typeDescriptor)
                          throws TypeMismatchException
        将该值转换为所需的类型

        注意:requiredType 或 typeDescriptor 必须有一个不为空!

        参数:
        source - 要转换的值
        requiredType - 必须转换为的类型 (如果不知道,则为null,例如在集合元素的情况下)
        typeDescriptor - 要使用的类型描述符(可能是null))
        返回:
        类型转换的结果
        抛出:
        TypeMismatchException - 如果类型转换失败,则抛出该例外