Skip to content

Commit 1c5e074

Browse files
authored
Return immutable Set for a Collection (#974)
* Return immutable Set for a Collection Fixes #965
1 parent f1fde23 commit 1c5e074

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

api/src/main/java/io/jsonwebtoken/lang/Collections.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,19 +86,16 @@ public static <T> List<T> of(T... elements) {
8686
/**
8787
* Returns the specified collection as a {@link Set} instance.
8888
*
89-
* @param c the collection to represent as a set
89+
* @param c the collection to be converted
9090
* @param <T> collection element type
91-
* @return a type-safe immutable {@code Set} containing the specified collection elements.
91+
* @return a type-safe immutable {@code Set} containing the specified collection elements.
9292
* @since 0.12.0
9393
*/
9494
public static <T> Set<T> asSet(Collection<T> c) {
95-
if (c instanceof Set) {
96-
return (Set<T>) c;
97-
}
9895
if (isEmpty(c)) {
9996
return java.util.Collections.emptySet();
10097
}
101-
return java.util.Collections.unmodifiableSet(new LinkedHashSet<>(c));
98+
return java.util.Collections.unmodifiableSet(new LinkedHashSet<T>(c));
10299
}
103100

104101
/**

0 commit comments

Comments
 (0)