delegate)"
// to work around an Eclipse type inference bug: https://github.com/google/dagger/issues/949.
public static , T> Provider provider(P delegate) {
checkNotNull(delegate);
if (delegate instanceof DoubleCheck) {
/* This should be a rare case, but if we have a scoped @Binds that delegates to a scoped
* binding, we shouldn't cache the value again. */
return delegate;
}
return new DoubleCheck(delegate);
}
/** Returns a {@link Lazy} that caches the value from the given provider. */
// This method is declared this way instead of " Lazy lazy(Provider delegate)"
// to work around an Eclipse type inference bug: https://github.com/google/dagger/issues/949.
public static , T> Lazy lazy(P provider) {
if (provider instanceof Lazy) {
@SuppressWarnings("unchecked")
final Lazy lazy = (Lazy) provider;
// Avoids memoizing a value that is already memoized.
// NOTE: There is a pathological case where Provider may implement Lazy, but P and L
// are different types using covariant return on get(). Right now this is used with
// DoubleCheck exclusively, which is implemented such that P and L are always
// the same, so it will be fine for that case.
return lazy;
}
return new DoubleCheck(checkNotNull(provider));
}
}