| 构造器和说明 |
|---|
Try() |
| 限定符和类型 | 方法和说明 |
|---|---|
abstract Try<Exception> |
failed()
Inverts this `Try`.
|
abstract Try<T> |
filter(java.util.function.Predicate<T> p)
Converts this to a `Failure` if the predicate is not satisfied.
|
abstract <U> Try<U> |
flatMap(java.util.function.Function<T,Try<U>> f)
Returns the given function applied to the value from this `Success` or returns this if this is a `Failure`.
|
abstract Try<T> |
foreach(java.util.function.Consumer<T> f)
Applies the given function `f` if this is a `Success`, otherwise returns `Unit` if this is a `Failure`.
|
abstract T |
get()
Returns the value from this `Success` or throws the exception if this is a `Failure`.
|
T |
getOrElse(java.util.function.Supplier<T> defaultValue)
Returns the value from this `Success` or the given `default` argument if this is a `Failure`.
|
T |
getOrElse(T defaultValue)
Returns the value from this `Success` or the given `default` argument if this is a `Failure`.
|
abstract boolean |
isFailure()
Returns `true` if the `Try` is a `Failure`, `false` otherwise.
|
abstract boolean |
isSuccess()
Returns `true` if the `Try` is a `Success`, `false` otherwise.
|
abstract <U> Try<U> |
map(java.util.function.Function<T,U> f)
Maps the given function to the value from this `Success` or returns this if this is a `Failure`.
|
static <T> Try<T> |
of(T value) |
static <T extends Exception> |
ofFailure(T value) |
abstract Try<T> |
onException(java.util.function.Consumer<Exception> f) |
Try<T> |
orElse(java.util.function.Supplier<Try<T>> defaultValue)
Returns this `Try` if it's a `Success` or the given `default` argument if this is a `Failure`.
|
Try<T> |
orElse(Try<T> defaultValue)
Returns this `Try` if it's a `Success` or the given `default` argument if this is a `Failure`.
|
abstract Try<T> |
recover(java.util.function.Function<Exception,T> f)
Applies the given function `f` if this is a `Failure`, otherwise returns this if this is a `Success`.
|
abstract Try<T> |
recoverWith(java.util.function.Function<Exception,Try<T>> f)
Applies the given function `f` if this is a `Failure`, otherwise returns this if this is a `Success`.
|
static Try<Void> |
to(RunnableThrow<Exception> code) |
static Try<Void> |
to(RunnableThrow<Exception> code,
RunnableThrow<Exception> onFinally) |
static <T> Try<T> |
to(SupplierThrow<T,Exception> code) |
static <T> Try<T> |
to(SupplierThrow<T,Exception> code,
RunnableThrow<Exception> onFinally)
Constructs a `Try` using a code as a supplier.
|
Optional<T> |
toOptional()
Returns `None` if this is a `Failure` or a `Some` containing the value if this is a `Success`.
|
abstract <U> Try<U> |
transform(java.util.function.Function<T,Try<U>> s,
java.util.function.Function<Exception,Try<U>> f)
Completes this `Try` by applying the function `f` to this if this is of type `Failure`, or conversely, by applying
`s` if this is a `Success`.
|
public static <T> Try<T> to(SupplierThrow<T,Exception> code, RunnableThrow<Exception> onFinally)
public static <T> Try<T> to(SupplierThrow<T,Exception> code)
public static Try<Void> to(RunnableThrow<Exception> code, RunnableThrow<Exception> onFinally)
public static Try<Void> to(RunnableThrow<Exception> code)
public static <T> Try<T> of(T value)
public abstract boolean isFailure()
public abstract boolean isSuccess()
public T getOrElse(java.util.function.Supplier<T> defaultValue)
''Note:'': This will throw an exception if it is not a success and default throws an exception.
public T getOrElse(T defaultValue)
''Note:'': This will throw an exception if it is not a success and default throws an exception.
public Try<T> orElse(java.util.function.Supplier<Try<T>> defaultValue)
public Try<T> orElse(Try<T> defaultValue)
public abstract T get()
public abstract Try<T> foreach(java.util.function.Consumer<T> f)
''Note:'' If `f` throws, then this method may throw an exception.
public abstract Try<T> onException(java.util.function.Consumer<Exception> f)
public abstract <U> Try<U> flatMap(java.util.function.Function<T,Try<U>> f)
public abstract <U> Try<U> map(java.util.function.Function<T,U> f)
public abstract Try<T> filter(java.util.function.Predicate<T> p)
public abstract Try<T> recoverWith(java.util.function.Function<Exception,Try<T>> f)
public abstract Try<T> recover(java.util.function.Function<Exception,T> f)
public Optional<T> toOptional()
public abstract Try<Exception> failed()
public abstract <U> Try<U> transform(java.util.function.Function<T,Try<U>> s, java.util.function.Function<Exception,Try<U>> f)
Copyright © 2017. All rights reserved.