@Beta @CheckReturnValue public abstract class Produced<T> extends Object
T
,
or an exception that was thrown during that production. For any type T
that can be
injected, you can also inject Produced<T>
, which enables handling of any exceptions that
were thrown during the production of T
.
For example:
@Produces Html getResponse(
UserInfo criticalInfo, Produced<ExtraInfo> noncriticalInfo) {
try {
return new Html(criticalInfo, noncriticalInfo.get());
} catch (ExecutionException e) {
logger.warning(e, "Noncritical info");
return new Html(criticalInfo);
}
}
Modifier and Type | Method and Description |
---|---|
abstract boolean |
equals(Object o)
Two
Produced objects compare equal if both are successful with equal values, or both
are failed with equal exceptions. |
static <T> Produced<T> |
failed(Throwable throwable)
|
abstract T |
get()
Returns the result of a production.
|
abstract int |
hashCode()
Returns an appropriate hash code to match
equals(Object) . |
static <T> Produced<T> |
successful(T value)
Returns a successful
Produced , whose get() will return the given value. |
public abstract T get() throws ExecutionException
ExecutionException
- if the production threw an exceptionpublic abstract boolean equals(Object o)
Produced
objects compare equal if both are successful with equal values, or both
are failed with equal exceptions.public abstract int hashCode()
equals(Object)
.public static <T> Produced<T> successful(@NullableDecl T value)
Produced
, whose get()
will return the given value.Copyright © 2012–2017 The Dagger Authors. All rights reserved.