Class Produced<T>

java.lang.Object
dagger.producers.Produced<T>

@Beta @CheckReturnValue public abstract class Produced<T> extends Object
An interface that represents the result of a production of type 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);
     }
   }
 
Since:
2.0
  • Method Summary

    Modifier and Type
    Method
    Description
    abstract boolean
    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)
    Returns a failed Produced, whose get() will throw an ExecutionException with the given cause.
    abstract T
    get()
    Returns the result of a production.
    abstract int
    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.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • get

      public abstract T get() throws ExecutionException
      Returns the result of a production.
      Throws:
      ExecutionException - if the production threw an exception
    • equals

      public abstract boolean equals(Object o)
      Two Produced objects compare equal if both are successful with equal values, or both are failed with equal exceptions.
      Overrides:
      equals in class Object
    • hashCode

      public abstract int hashCode()
      Returns an appropriate hash code to match equals(Object).
      Overrides:
      hashCode in class Object
    • successful

      public static <T> Produced<T> successful(@NullableDecl T value)
      Returns a successful Produced, whose get() will return the given value.
    • failed

      public static <T> Produced<T> failed(Throwable throwable)
      Returns a failed Produced, whose get() will throw an ExecutionException with the given cause.