Skip to content

Commit df5eb3a

Browse files
eamonnmcmanusronshapiro
authored andcommitted
Document MoreTypes.equivalence().
RELNOTES=Document MoreTypes.equivalence(). ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=189631496
1 parent 3fec796 commit df5eb3a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

common/src/main/java/com/google/auto/common/MoreTypes.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,21 @@ protected int doHash(TypeMirror t) {
8080
}
8181
}
8282

83+
/**
84+
* Returns an {@link Equivalence} that can be used to compare types. The standard way to compare
85+
* types is {@link javax.lang.model.util.Types#isSameType Types.isSameType}, but this alternative
86+
* may be preferred in a number of cases:
87+
*
88+
* <ul>
89+
* <li>If you don't have an instance of {@code Types}.
90+
* <li>If you want a reliable {@code hashCode()} for the types, for example to construct a set
91+
* of types using {@link java.util.HashSet} with {@link Equivalence#wrap()}.
92+
* <li>If you want distinct type variables to be considered equal if they have the same names
93+
* and bounds.
94+
* <li>If you want wildcard types to compare equal if they have the same bounds. {@code
95+
* Types.isSameType} never considers wildcards equal, even when comparing a type to itself.
96+
* </ul>
97+
*/
8398
public static Equivalence<TypeMirror> equivalence() {
8499
return TypeEquivalence.INSTANCE;
85100
}

0 commit comments

Comments
 (0)