Skip to content

Commit

Permalink
Annotate new, expected-size-based collection factory methods. (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpovirk authored Oct 7, 2024
1 parent 240af02 commit 2b3db41
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/HashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -2603,7 +2603,7 @@ static int calculateHashMapCapacity(int numMappings) {
* @throws IllegalArgumentException if numMappings is negative
* @since 19
*/
public static <K, V> HashMap<K, V> newHashMap(int numMappings) {
public static <K extends @Nullable Object, V extends @Nullable Object> HashMap<K, V> newHashMap(int numMappings) {
if (numMappings < 0) {
throw new IllegalArgumentException("Negative number of mappings: " + numMappings);
}
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/HashSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public Spliterator<E> spliterator() {
* @throws IllegalArgumentException if numElements is negative
* @since 19
*/
public static <T> HashSet<T> newHashSet(int numElements) {
public static <T extends @Nullable Object> HashSet<T> newHashSet(int numElements) {
if (numElements < 0) {
throw new IllegalArgumentException("Negative number of elements: " + numElements);
}
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/LinkedHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -1084,7 +1084,7 @@ final class LinkedEntryIterator extends LinkedHashIterator
* @throws IllegalArgumentException if numMappings is negative
* @since 19
*/
public static <K, V> LinkedHashMap<K, V> newLinkedHashMap(int numMappings) {
public static <K extends @Nullable Object, V extends @Nullable Object> LinkedHashMap<K, V> newLinkedHashMap(int numMappings) {
if (numMappings < 0) {
throw new IllegalArgumentException("Negative number of mappings: " + numMappings);
}
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/LinkedHashSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ public Spliterator<E> spliterator() {
* @throws IllegalArgumentException if numElements is negative
* @since 19
*/
public static <T> LinkedHashSet<T> newLinkedHashSet(int numElements) {
public static <T extends @Nullable Object> LinkedHashSet<T> newLinkedHashSet(int numElements) {
if (numElements < 0) {
throw new IllegalArgumentException("Negative number of elements: " + numElements);
}
Expand Down
2 changes: 1 addition & 1 deletion src/java.base/share/classes/java/util/WeakHashMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ public int characteristics() {
* @throws IllegalArgumentException if numMappings is negative
* @since 19
*/
public static <K, V> WeakHashMap<K, V> newWeakHashMap(int numMappings) {
public static <K extends @Nullable Object, V extends @Nullable Object> WeakHashMap<K, V> newWeakHashMap(int numMappings) {
if (numMappings < 0) {
throw new IllegalArgumentException("Negative number of mappings: " + numMappings);
}
Expand Down

0 comments on commit 2b3db41

Please sign in to comment.