@@ -179,7 +179,7 @@ public static <E> Collection<E> createCollection(Class<?> collectionType, int ca
179
179
@ SuppressWarnings ("unchecked" )
180
180
public static <E > Collection <E > createCollection (Class <?> collectionType , @ Nullable Class <?> elementType , int capacity ) {
181
181
Assert .notNull (collectionType , "Collection type must not be null" );
182
- if (LinkedHashSet .class == collectionType || HashSet . class == collectionType ||
182
+ if (LinkedHashSet .class == collectionType ||
183
183
Set .class == collectionType || Collection .class == collectionType ) {
184
184
return new LinkedHashSet <>(capacity );
185
185
}
@@ -197,6 +197,9 @@ else if (EnumSet.class.isAssignableFrom(collectionType)) {
197
197
Assert .notNull (elementType , "Cannot create EnumSet for unknown element type" );
198
198
return EnumSet .noneOf (asEnumType (elementType ));
199
199
}
200
+ else if (HashSet .class == collectionType ) {
201
+ return new HashSet <>(capacity );
202
+ }
200
203
else {
201
204
if (collectionType .isInterface () || !Collection .class .isAssignableFrom (collectionType )) {
202
205
throw new IllegalArgumentException ("Unsupported Collection type: " + collectionType .getName ());
@@ -297,7 +300,7 @@ public static <K, V> Map<K, V> createMap(Class<?> mapType, int capacity) {
297
300
@ SuppressWarnings ({"rawtypes" , "unchecked" })
298
301
public static <K , V > Map <K , V > createMap (Class <?> mapType , @ Nullable Class <?> keyType , int capacity ) {
299
302
Assert .notNull (mapType , "Map type must not be null" );
300
- if (LinkedHashMap .class == mapType || HashMap . class == mapType || Map .class == mapType ) {
303
+ if (LinkedHashMap .class == mapType || Map .class == mapType ) {
301
304
return new LinkedHashMap <>(capacity );
302
305
}
303
306
else if (LinkedMultiValueMap .class == mapType || MultiValueMap .class == mapType ) {
@@ -310,6 +313,9 @@ else if (EnumMap.class == mapType) {
310
313
Assert .notNull (keyType , "Cannot create EnumMap for unknown key type" );
311
314
return new EnumMap (asEnumType (keyType ));
312
315
}
316
+ else if (HashMap .class == mapType ) {
317
+ return new HashMap <>(capacity );
318
+ }
313
319
else {
314
320
if (mapType .isInterface () || !Map .class .isAssignableFrom (mapType )) {
315
321
throw new IllegalArgumentException ("Unsupported Map type: " + mapType .getName ());
0 commit comments