Class Try.Success<T>
java.lang.Object
cloud.opencode.base.functional.monad.Try.Success<T>
- Type Parameters:
T- value type - 值类型
- All Implemented Interfaces:
Try<T>
Success - Represents a successful computation
Success - 表示成功的计算
- 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 TypeMethodDescriptionbooleanFilter 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 如果成功则转换值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()value()Get the contained value 获取包含的值Methods inherited from interface Try
andFinally, contains, exists, fold, mapFailure, stream, toOption, toValidation
-
Constructor Details
-
Success
-
-
Method Details
-
value
-
isSuccess
-
isFailure
-
get
-
getCause
-
map
-
flatMap
Description copied from interface:TryTransform the value to another Try if Success 如果成功则转换为另一个 Try -
filter
-
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
-