Skip to content

Commit c5255f1

Browse files
cpovirkGoogle Java Core Libraries
authored andcommitted
Discourage Function.identity().
RELNOTES=n/a PiperOrigin-RevId: 543821637
1 parent f9a29d7 commit c5255f1

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

android/guava/src/com/google/common/base/Functions.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ public String toString() {
7979
}
8080
}
8181

82-
/** Returns the identity function. */
82+
/**
83+
* Returns the identity function.
84+
*
85+
* <p><b>Discouraged:</b> Prefer using a lambda like {@code v -> v}, which is shorter and often
86+
* more readable.
87+
*/
8388
// implementation is "fully variant"; E has become a "pass-through" type
8489
@SuppressWarnings("unchecked")
8590
public static <E extends @Nullable Object> Function<E, E> identity() {

guava/src/com/google/common/base/Functions.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,12 @@ public String toString() {
7979
}
8080
}
8181

82-
/** Returns the identity function. */
82+
/**
83+
* Returns the identity function.
84+
*
85+
* <p><b>Discouraged:</b> Prefer using a lambda like {@code v -> v}, which is shorter and often
86+
* more readable.
87+
*/
8388
// implementation is "fully variant"; E has become a "pass-through" type
8489
@SuppressWarnings("unchecked")
8590
public static <E extends @Nullable Object> Function<E, E> identity() {

0 commit comments

Comments
 (0)