Skip to content

Commit fc54121

Browse files
klueverGoogle Java Core Libraries
authored andcommitted
mention target::contains in Predicates.in()'s javadocs.
RELNOTES=n/a PiperOrigin-RevId: 742818259
1 parent e24ae35 commit fc54121

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ public static Predicate<Class<?>> subtypeOf(Class<?> clazz) {
208208
* helps prevent bugs. This approach doesn't block any potential users since it is always possible
209209
* to use {@code Predicates.<Object>in()}.
210210
*
211+
* <p>You may prefer to use a method reference (e.g., {@code target::contains}) instead of this
212+
* method. However, there are some subtle considerations:
213+
*
214+
* <ul>
215+
* <li>The {@link Predicate} returned by this method is {@link Serializable}.
216+
* <li>The {@link Predicate} returned by this method catches {@link ClassCastException} and
217+
* {@link NullPointerException}.
218+
* <li>Code that chains multiple predicates together (especially negations) may be more readable
219+
* using this method. For example, {@code not(in(target))} is generally more readable than
220+
* {@code not(target::contains)}.
221+
* <li>This method's name conflicts with Kotlin's {@code in} operator.
222+
* </ul>
223+
*
211224
* @param target the collection that may contain the function input
212225
*/
213226
@SuppressWarnings("NoHardKeywords") // We're stuck with the name for compatibility reasons.

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,19 @@ public static Predicate<Class<?>> subtypeOf(Class<?> clazz) {
208208
* helps prevent bugs. This approach doesn't block any potential users since it is always possible
209209
* to use {@code Predicates.<Object>in()}.
210210
*
211+
* <p>You may prefer to use a method reference (e.g., {@code target::contains}) instead of this
212+
* method. However, there are some subtle considerations:
213+
*
214+
* <ul>
215+
* <li>The {@link Predicate} returned by this method is {@link Serializable}.
216+
* <li>The {@link Predicate} returned by this method catches {@link ClassCastException} and
217+
* {@link NullPointerException}.
218+
* <li>Code that chains multiple predicates together (especially negations) may be more readable
219+
* using this method. For example, {@code not(in(target))} is generally more readable than
220+
* {@code not(target::contains)}.
221+
* <li>This method's name conflicts with Kotlin's {@code in} operator.
222+
* </ul>
223+
*
211224
* @param target the collection that may contain the function input
212225
*/
213226
@SuppressWarnings("NoHardKeywords") // We're stuck with the name for compatibility reasons.

0 commit comments

Comments
 (0)