@@ -183,7 +183,7 @@ public static <E> Collection<E> createCollection(Class<?> collectionType, int ca
183
183
@ SuppressWarnings ({"unchecked" , "cast" })
184
184
public static <E > Collection <E > createCollection (Class <?> collectionType , @ Nullable Class <?> elementType , int capacity ) {
185
185
Assert .notNull (collectionType , "Collection type must not be null" );
186
- if (LinkedHashSet .class == collectionType || HashSet . class == collectionType ||
186
+ if (LinkedHashSet .class == collectionType ||
187
187
Set .class == collectionType || Collection .class == collectionType ) {
188
188
return new LinkedHashSet <>(capacity );
189
189
}
@@ -202,6 +202,9 @@ else if (EnumSet.class.isAssignableFrom(collectionType)) {
202
202
// Cast is necessary for compilation in Eclipse 4.4.1.
203
203
return (Collection <E >) EnumSet .noneOf (asEnumType (elementType ));
204
204
}
205
+ else if (HashSet .class == collectionType ) {
206
+ return new HashSet <>(capacity );
207
+ }
205
208
else {
206
209
if (collectionType .isInterface () || !Collection .class .isAssignableFrom (collectionType )) {
207
210
throw new IllegalArgumentException ("Unsupported Collection type: " + collectionType .getName ());
@@ -302,7 +305,7 @@ public static <K, V> Map<K, V> createMap(Class<?> mapType, int capacity) {
302
305
@ SuppressWarnings ({"rawtypes" , "unchecked" })
303
306
public static <K , V > Map <K , V > createMap (Class <?> mapType , @ Nullable Class <?> keyType , int capacity ) {
304
307
Assert .notNull (mapType , "Map type must not be null" );
305
- if (LinkedHashMap .class == mapType || HashMap . class == mapType || Map .class == mapType ) {
308
+ if (LinkedHashMap .class == mapType || Map .class == mapType ) {
306
309
return new LinkedHashMap <>(capacity );
307
310
}
308
311
else if (LinkedMultiValueMap .class == mapType || MultiValueMap .class == mapType ) {
@@ -315,6 +318,9 @@ else if (EnumMap.class == mapType) {
315
318
Assert .notNull (keyType , "Cannot create EnumMap for unknown key type" );
316
319
return new EnumMap (asEnumType (keyType ));
317
320
}
321
+ else if (HashMap .class == mapType ) {
322
+ return new HashMap <>(capacity );
323
+ }
318
324
else {
319
325
if (mapType .isInterface () || !Map .class .isAssignableFrom (mapType )) {
320
326
throw new IllegalArgumentException ("Unsupported Map type: " + mapType .getName ());
0 commit comments