Package dagger.producers
Class Produced<T>
- java.lang.Object
-
- dagger.producers.Produced<T>
-
@Beta @CheckReturnValue public abstract class Produced<T> extends java.lang.Object
An interface that represents the result of a production of typeT
, or an exception that was thrown during that production. For any typeT
that can be injected, you can also injectProduced<T>
, which enables handling of any exceptions that were thrown during the production ofT
.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); } }
- Since:
- 2.0
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract boolean
equals(java.lang.Object o)
TwoProduced
objects compare equal if both are successful with equal values, or both are failed with equal exceptions.static <T> Produced<T>
failed(java.lang.Throwable throwable)
abstract T
get()
Returns the result of a production.abstract int
hashCode()
Returns an appropriate hash code to matchequals(Object)
.static <T> Produced<T>
successful(T value)
Returns a successfulProduced
, whoseget()
will return the given value.
-
-
-
Method Detail
-
get
public abstract T get() throws java.util.concurrent.ExecutionException
Returns the result of a production.- Throws:
java.util.concurrent.ExecutionException
- if the production threw an exception
-
equals
public abstract boolean equals(java.lang.Object o)
TwoProduced
objects compare equal if both are successful with equal values, or both are failed with equal exceptions.- Overrides:
equals
in classjava.lang.Object
-
hashCode
public abstract int hashCode()
Returns an appropriate hash code to matchequals(Object)
.- Overrides:
hashCode
in classjava.lang.Object
-
successful
public static <T> Produced<T> successful(@NullableDecl T value)
Returns a successfulProduced
, whoseget()
will return the given value.
-
failed
public static <T> Produced<T> failed(java.lang.Throwable throwable)
-
-