Instances of this class should be returned by methods instead of
Optional when callers might want to report the exception via logging
or by wrapping it in another exception at a later point in time, e.g. via
getOrThrow(Function).
Moreover, it makes it particularly convenient to attach follow-up actions
should the Try have been successful (cf. andThen and
andThenTry) or fallback actions should it not have been (cf.
orElse and orElseTry).
| Modifier and Type | Class and Description |
|---|---|
| private static class | |
| private static class | |
| public static interface | Try.
A transformer for values of type |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public abstract <U> Try | |
| public abstract <U> Try | Returns: a succeeded or failedTry; never nullthe transformer to try; must not be transformernullIf this |
| public static <V extends @Nullable Object> Try | Returns: a succeeded or failedTry depending on the outcome of the
supplied action; never nullthe action to try; must not be action)nullCall the supplied |
| private static <T> T | |
| public static <V> Try | |
| public abstract V | Returns: the contained value, if available; potentiallynullIf this |
| public final @NonNull V | Returns: the contained value, if availableIf this |
| public final <E extends Exception> @NonNull V | Returns: the contained value, if available and notnullthe transformer to be called with the
contained exception, if available; must not be exceptionTransformer)nullIf this |
| public abstract <E extends Exception> V | Returns: the contained value, if availablethe transformer to be called with the
contained exception, if available; must not be exceptionTransformer)nullIf this |
| public abstract Try | |
| public abstract Try | |
| private static <V> Try | |
| public abstract Try | |
| public abstract Try | |
| public static <V extends @Nullable Object> Try | Returns: a succeededTry that contains the supplied value; never
nullthe value to wrap; potentially value)nullConvert the supplied value into a succeeded |
| public abstract Optional | toOptional()
If this |
| Try | back to summary |
|---|---|
| private Try() | |
| andThen | back to summary |
|---|---|
| public abstract <U> Try If this | |
| andThenTry | back to summary |
|---|---|
| public abstract <U> Try If this
| |
| call | back to summary |
|---|---|
| public static <V extends @Nullable Object> Try Call the supplied
| |
| checkNotNull | back to summary |
|---|---|
private static <T> T checkNotNull(@Nullable T input, String title)
| |
| failure | back to summary |
|---|---|
| public static <V> Try Convert the supplied exception into a failed | |
| get | back to summary |
|---|---|
| public abstract V get() throws Exception If this
| |
| getNonNull | back to summary |
|---|---|
| public final @NonNull V getNonNull() throws Exception If this
| |
| getNonNullOrThrow | back to summary |
|---|---|
| public final <E extends Exception> @NonNull V getNonNullOrThrow(Function<@Nullable Exception, E> exceptionTransformer) throws Function-:E If this
| |
| getOrThrow | back to summary |
|---|---|
| public abstract <E extends Exception> V getOrThrow(Function<? super Exception, E> exceptionTransformer) throws Function-:E If this
| |
| ifFailure | back to summary |
|---|---|
| public abstract Try If this | |
| ifSuccess | back to summary |
|---|---|
| public abstract Try If this | |
| of | back to summary |
|---|---|
| private static <V> Try | |
| orElse | back to summary |
|---|---|
| public abstract Try If this | |
| orElseTry | back to summary |
|---|---|
| public abstract Try If this | |
| success | back to summary |
|---|---|
| public static <V extends @Nullable Object> Try Convert the supplied value into a succeeded
| |
| toOptional | back to summary |
|---|---|
| public abstract Optional If this | |
| Modifier and Type | Method and Description |
|---|---|
| public <U> Try | andThen(Function<V, Try<U>> function)
Implements abstract org. If this |
| public <U> Try | andThenTry(Try.
Implements abstract org. If this |
| public boolean | equals(Object that)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public V | get()
Implements abstract org. If this |
| public <E extends Exception> V | getOrThrow(Function<? super Exception, E> exceptionTransformer)
Implements abstract org. If this |
| public int | |
| public Try | ifFailure(Consumer<Exception> causeConsumer)
Implements abstract org. If this |
| public Try | ifSuccess(Consumer<V> valueConsumer)
Implements abstract org. If this |
| public Try | orElse(Supplier<Try<V>> supplier)
Implements abstract org. If this |
| public Try | orElseTry(Callable<V> action)
Implements abstract org. If this |
| public Optional | toOptional()
Implements abstract org. If this |
| private <U> Try |
| cause | back to summary |
|---|---|
| private final Exception cause | |
| Failure | back to summary |
|---|---|
| pack-priv Failure(Exception cause) | |
| andThen | back to summary |
|---|---|
| public <U> Try Implements abstract org. Doc from org. If this
| |
| andThenTry | back to summary |
|---|---|
| public <U> Try Implements abstract org. Doc from org. If this
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object that) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| get | back to summary |
|---|---|
| public V get() throws Exception Implements abstract org. Doc from org. If this | |
| getOrThrow | back to summary |
|---|---|
| public <E extends Exception> V getOrThrow(Function<? super Exception, E> exceptionTransformer) throws Function-:E Implements abstract org. Doc from org. If this | |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| ifFailure | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| ifSuccess | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| orElse | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| orElseTry | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| toOptional | back to summary |
|---|---|
| public Optional Implements abstract org. Doc from org. If this
| |
| uncheckedCast | back to summary |
|---|---|
private <U> Try
| |
| Modifier and Type | Field and Description |
|---|---|
| private final V |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public <U> Try | andThen(Function<V, Try<U>> function)
Implements abstract org. If this |
| public <U> Try | andThenTry(Try.
Implements abstract org. If this |
| public boolean | equals(Object that)
Overrides java. Indicates whether some other object is "equal to" this one. |
| public V | get()
Implements abstract org. If this |
| public <E extends Exception> V | getOrThrow(Function<? super Exception, E> exceptionTransformer)
Implements abstract org. If this |
| public int | |
| public Try | ifFailure(Consumer<Exception> causeConsumer)
Implements abstract org. If this |
| public Try | ifSuccess(Consumer<V> valueConsumer)
Implements abstract org. If this |
| public Try | orElse(Supplier<Try<V>> supplier)
Implements abstract org. If this |
| public Try | orElseTry(Callable<V> action)
Implements abstract org. If this |
| public Optional | toOptional()
Implements abstract org. If this |
| value | back to summary |
|---|---|
| private final V value | |
| Success | back to summary |
|---|---|
| pack-priv Success(V value) | |
| andThen | back to summary |
|---|---|
| public <U> Try Implements abstract org. Doc from org. If this
| |
| andThenTry | back to summary |
|---|---|
| public <U> Try Implements abstract org. Doc from org. If this
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object that) Overrides java. Doc from java. Indicates whether some other object is "equal to" this one.
The
An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.
| |
| get | back to summary |
|---|---|
| public V get() Implements abstract org. Doc from org. If this
| |
| getOrThrow | back to summary |
|---|---|
| public <E extends Exception> V getOrThrow(Function<? super Exception, E> exceptionTransformer) Implements abstract org. Doc from org. If this
| |
| hashCode | back to summary |
|---|---|
| public int hashCode() Overrides java. Doc from java. Returns a hash code value for this object. This method is
supported for the benefit of hash tables such as those provided by
The general contract of
| |
| ifFailure | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| ifSuccess | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| orElse | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| orElseTry | back to summary |
|---|---|
| public Try Implements abstract org. Doc from org. If this
| |
| toOptional | back to summary |
|---|---|
| public Optional Implements abstract org. Doc from org. If this
| |
S to type T.
The Transformer interface is similar to Function,
except that a Transformer may throw an exception.
| Modifier and Type | Method and Description |
|---|---|
| public T |
| apply | back to summary |
|---|---|
| public T apply(S value) throws Exception Apply this transformer to the supplied value.
| |