@@ -73,33 +73,36 @@ public static boolean isEmpty(@Nullable Map<?, ?> map) {
73
73
74
74
/**
75
75
* Instantiate a new {@link HashMap} with an initial capacity
76
- * that can accommodate the given number of elements.
76
+ * that can accommodate the specified number of elements without
77
+ * any immediate resize/rehash operations to be expected.
77
78
* <p>This differs from the regular {@link HashMap} constructor
78
79
* which takes an initial capacity relative to a load factor
79
80
* but is effectively aligned with the JDK's
80
81
* {@link java.util.concurrent.ConcurrentHashMap#ConcurrentHashMap(int)}.
81
- * @param expectedSize the expected number of elements
82
+ * @param expectedSize the expected number of elements (with a corresponding
83
+ * capacity to be derived so that no resize/rehash operations are needed)
82
84
* @since 5.3
83
85
* @see #newLinkedHashMap(int)
84
86
*/
85
- @ SuppressWarnings ({"rawtypes" , "unchecked" })
86
87
public static <K , V > HashMap <K , V > newHashMap (int expectedSize ) {
87
- return new HashMap ((int ) (expectedSize / DEFAULT_LOAD_FACTOR ), DEFAULT_LOAD_FACTOR );
88
+ return new HashMap <> ((int ) (expectedSize / DEFAULT_LOAD_FACTOR ), DEFAULT_LOAD_FACTOR );
88
89
}
89
90
90
91
/**
91
92
* Instantiate a new {@link LinkedHashMap} with an initial capacity
92
- * that can accommodate the given number of elements.
93
+ * that can accommodate the specified number of elements without
94
+ * any immediate resize/rehash operations to be expected.
93
95
* <p>This differs from the regular {@link LinkedHashMap} constructor
94
96
* which takes an initial capacity relative to a load factor but is
95
97
* aligned with Spring's own {@link LinkedCaseInsensitiveMap} and
96
98
* {@link LinkedMultiValueMap} constructor semantics as of 5.3.
97
- * @param expectedSize the expected number of elements
99
+ * @param expectedSize the expected number of elements (with a corresponding
100
+ * capacity to be derived so that no resize/rehash operations are needed)
98
101
* @since 5.3
102
+ * @see #newHashMap(int)
99
103
*/
100
- @ SuppressWarnings ({"rawtypes" , "unchecked" })
101
104
public static <K , V > LinkedHashMap <K , V > newLinkedHashMap (int expectedSize ) {
102
- return new LinkedHashMap ((int ) (expectedSize / DEFAULT_LOAD_FACTOR ), DEFAULT_LOAD_FACTOR );
105
+ return new LinkedHashMap <> ((int ) (expectedSize / DEFAULT_LOAD_FACTOR ), DEFAULT_LOAD_FACTOR );
103
106
}
104
107
105
108
/**
0 commit comments