From 781eb2a6e61cbb10d0b396b872b4784a7304b1af Mon Sep 17 00:00:00 2001 From: Patrick Strawderman Date: Thu, 14 May 2026 11:12:48 -0500 Subject: [PATCH] Short-circuit TypeToken#equals for same instance comparison Avoid delegating to the runtime type's equals implementation in TypeToken#equals for identical instances of TypeTokens. --- guava/src/com/google/common/reflect/TypeToken.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/guava/src/com/google/common/reflect/TypeToken.java b/guava/src/com/google/common/reflect/TypeToken.java index e9f61b0c489e..589885b9ce28 100644 --- a/guava/src/com/google/common/reflect/TypeToken.java +++ b/guava/src/com/google/common/reflect/TypeToken.java @@ -836,6 +836,9 @@ public boolean apply(TypeToken type) { */ @Override public boolean equals(@Nullable Object o) { + if (o == this) { + return true; + } if (o instanceof TypeToken) { TypeToken that = (TypeToken) o; return runtimeType.equals(that.runtimeType);