Skip to content

Commit

Permalink
Use more general type for DoubleCheck.provider() (and SingleCheck) to…
Browse files Browse the repository at this point in the history
… satisfy Java 9 Eclipse JDT type inference quirks

Fixes #949
Closes #957

RELNOTES=Fixed a compilation issue with eclipse

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=178773557
  • Loading branch information
facboy authored and ronshapiro committed Dec 14, 2017
1 parent bc40bc8 commit 4e74fce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 6 additions & 2 deletions java/dagger/internal/DoubleCheck.java
Expand Up @@ -65,7 +65,9 @@ public T get() {
}

/** Returns a {@link Provider} that caches the value from the given delegate provider. */
public static <T> Provider<T> provider(Provider<T> delegate) {
// This method is declared this way instead of "<T> Provider<T> provider(Provider<T> delegate)"
// to work around an Eclipse type inference bug: https://github.com/google/dagger/issues/949.
public static <P extends Provider<T>, T> Provider<T> 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
Expand All @@ -76,7 +78,9 @@ public static <T> Provider<T> provider(Provider<T> delegate) {
}

/** Returns a {@link Lazy} that caches the value from the given provider. */
public static <T> Lazy<T> lazy(Provider<T> provider) {
// This method is declared this way instead of "<T> Lazy<T> lazy(Provider<T> delegate)"
// to work around an Eclipse type inference bug: https://github.com/google/dagger/issues/949.
public static <P extends Provider<T>, T> Lazy<T> lazy(P provider) {
if (provider instanceof Lazy) {
@SuppressWarnings("unchecked")
final Lazy<T> lazy = (Lazy<T>) provider;
Expand Down
4 changes: 3 additions & 1 deletion java/dagger/internal/SingleCheck.java
Expand Up @@ -54,7 +54,9 @@ public T get() {
}

/** Returns a {@link Provider} that caches the value from the given delegate provider. */
public static <T> Provider<T> provider(Provider<T> provider) {
// This method is declared this way instead of "<T> Provider<T> provider(Provider<T> provider)"
// to work around an Eclipse type inference bug: https://github.com/google/dagger/issues/949.
public static <P extends Provider<T>, T> Provider<T> provider(P provider) {
// If a scoped @Binds delegates to a scoped binding, don't cache the value again.
if (provider instanceof SingleCheck || provider instanceof DoubleCheck) {
return provider;
Expand Down

0 comments on commit 4e74fce

Please sign in to comment.