Class Try.Failure<T>
java.lang.Object
cloud.opencode.base.functional.monad.Try.Failure<T>
- Type Parameters:
T- value type - 值类型
- All Implemented Interfaces:
Try<T>
Failure - Represents a failed computation
Failure - 表示失败的计算
- Since:
- JDK 25, opencode-base-functional V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
-
Nested Class Summary
Nested classes/interfaces inherited from interface Try
Try.Failure<T>, Try.Success<T> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncause()Get the exception 获取异常booleanFilter the value with a predicate 使用谓词过滤值<U> Try<U> Transform the value to another Try if Success 如果成功则转换为另一个 Tryget()Get the value, throws if failure 获取值,失败时抛出异常getCause()Get the exception if this is a Failure 获取异常(如果失败)Get value or default if Failure 获取值或默认值(如果失败)inthashCode()booleanCheck if this is a Failure 检查是否失败booleanCheck if this is a Success 检查是否成功<U> Try<U> Transform the value if Success 如果成功则转换值mapFailure(Function<Throwable, ? extends Throwable> mapper) Transform the exception if this is a Failure.Execute action on failure 失败时执行操作Execute action on success 成功时执行操作Return this or other Try if Failure 返回本 Try 或其他 Try(如果失败)Execute action on the value if Success 如果成功则对值执行操作Recover from Failure with a function 使用函数从失败恢复recoverWith(Function<Throwable, Try<T>> recovery) Recover from Failure with a function returning Try 使用返回 Try 的函数从失败恢复toEither()Convert to Either (Left=exception, Right=value) 转换为 Either(Left=异常,Right=值)Convert to Optional (empty if Failure) 转换为 Optional(失败时为空)toString()Methods inherited from interface Try
andFinally, contains, exists, fold, stream, toOption, toValidation
-
Constructor Details
-
Failure
-
-
Method Details
-
cause
-
isSuccess
-
isFailure
-
get
-
getCause
-
map
-
flatMap
Description copied from interface:TryTransform the value to another Try if Success 如果成功则转换为另一个 Try -
filter
-
mapFailure
Description copied from interface:TryTransform the exception if this is a Failure. If Success, return this unchanged. 如果是 Failure 则转换异常。如果是 Success 则原样返回。If the mapper itself throws, returns a new
Try.Failurewrapping the mapper's exception, with the original cause added as a suppressed exception (mirroring try-with-resources semantics).如果 mapper 本身抛出异常,返回包装 mapper 异常的新
Try.Failure, 原始 cause 作为 suppressed 异常附加(类似 try-with-resources 语义)。- Specified by:
mapFailurein interfaceTry<T>- Parameters:
mapper- function to transform the exception - 转换异常的函数- Returns:
- Try with mapped exception if Failure, or this if Success | 如果是 Failure 返回转换后的异常,否则返回此 Try
-
getOrElse
-
orElse
-
recover
-
recoverWith
Description copied from interface:TryRecover from Failure with a function returning Try 使用返回 Try 的函数从失败恢复- Specified by:
recoverWithin interfaceTry<T>- Parameters:
recovery- recovery function returning Try - 返回 Try 的恢复函数- Returns:
- recovered Try
-
toOptional
-
toEither
-
peek
-
onFailure
-
onSuccess
-
equals
-
hashCode
-
toString
-