| 81 | // This method is declared this way instead of "<T> Lazy<T> lazy(Provider<T> delegate)" |
| 82 | // to work around an Eclipse type inference bug: https://github.com/google/dagger/issues/949. |
| 83 | public static <P extends Provider<T>, T> Lazy<T> lazy(P provider) { |
| 84 | if (provider instanceof Lazy) { |
| 85 | @SuppressWarnings("unchecked") |
| 86 | final Lazy<T> lazy = (Lazy<T>) provider; |
| 87 | // Avoids memoizing a value that is already memoized. |
| 88 | // NOTE: There is a pathological case where Provider<P> may implement Lazy<L>, but P and L |
| 89 | // are different types using covariant return on get(). Right now this is used with |
| 90 | // DoubleCheck<T> exclusively, which is implemented such that P and L are always |
| 91 | // the same, so it will be fine for that case. |
| 92 | return lazy; |
| 93 | } |
| 94 | return new DoubleCheck<T>(checkNotNull(provider)); |
| 95 | } |
| 96 | } |