diff options
| author | 2017-12-27 18:17:23 +0000 | |
|---|---|---|
| committer | 2017-12-27 18:17:23 +0000 | |
| commit | cb37da8b13a8f70942d253ac56a9ad3ae3cbf7ba (patch) | |
| tree | 112028e2a4cec42404c9415b7cc0d432c30f4ccc | |
| parent | 2301211526232de0f444160cdbde0da2ed3faeb9 (diff) | |
| parent | de8ca1ef94a82add0a5fa7c7dc923b8a5992a0e6 (diff) | |
Merge "Add a 'unbounded method refs only' clause to PooledLambda javadoc"
| -rwxr-xr-x | core/java/com/android/internal/util/function/pooled/PooledLambda.java | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/core/java/com/android/internal/util/function/pooled/PooledLambda.java b/core/java/com/android/internal/util/function/pooled/PooledLambda.java index 17b140dec396..87c25e9663d8 100755 --- a/core/java/com/android/internal/util/function/pooled/PooledLambda.java +++ b/core/java/com/android/internal/util/function/pooled/PooledLambda.java @@ -59,6 +59,21 @@ import java.util.function.Supplier; * You can fill the 'missing argument' spot with {@link #__()} * (which is the factory function for {@link ArgumentPlaceholder}) * + * NOTE: It is highly recommended to <b>only</b> use {@code ClassName::methodName} + * (aka unbounded method references) as the 1st argument for any of the + * factories ({@code obtain*(...)}) to avoid unwanted allocations. + * This means <b>not</b> using: + * <ul> + * <li>{@code someVar::methodName} or {@code this::methodName} as it captures the reference + * on the left of {@code ::}, resulting in an allocation on each evaluation of such + * bounded method references</li> + * + * <li>A lambda expression, e.g. {@code () -> toString()} due to how easy it is to accidentally + * capture state from outside. In the above lambda expression for example, no variable from + * outer scope is explicitly mentioned, yet one is still captured due to {@code toString()} + * being an equivalent of {@code this.toString()}</li> + * </ul> + * * @hide */ @SuppressWarnings({"unchecked", "unused", "WeakerAccess"}) |