File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed
core/src/com/google/inject/util Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change 39
39
@ CheckReturnValue
40
40
public final class Providers {
41
41
42
- private Providers () {}
43
-
44
42
/**
45
43
* Returns a provider which always provides {@code instance}. This should not be necessary to use
46
44
* in your application, but is helpful for several types of unit tests.
47
45
*
46
+ * <p><b>Java 8+ users:</b> prefer {@code () -> instance}. However, note the following
47
+ * differences:
48
+ *
49
+ * <ul>
50
+ * <li>Lambdas will delay evaluation of the instance. {@code () -> computeValue()} will be
51
+ * computed when {@code provider.get()} is called, but {@code Providers.of(computeValue())}
52
+ * will be computed immediately.
53
+ * <li>Lambdas do not implement {@code equals()} or {@code hashCode()}, so avoid putting them in
54
+ * a collection.
55
+ * <li>Lambdas do not implement a useful {@code toString()}.
56
+ * </ul>
57
+ *
48
58
* @param instance the instance that should always be provided. This is also permitted to be null,
49
59
* to enable aggressive testing, although in real life a Guice-supplied Provider will never
50
60
* return null.
@@ -173,4 +183,6 @@ public Set<Dependency<?>> getDependencies() {
173
183
return dependencies ;
174
184
}
175
185
}
186
+
187
+ private Providers () {}
176
188
}
You can’t perform that action at this time.
0 commit comments