-
Enhancement
-
Resolution: Won't Fix
-
P4
-
None
-
8
A DESCRIPTION OF THE PROBLEM :
Just as there is the method java.util.Objects.requireNonNull (..), it would be great if there is a similar method for collections that checks whether the collection is not null or empty.
Java pseudocode:
class java.util.Collections {
public static <T extends java.util.Collection<?>> T getNotEmpty( T collection) {
// Check if collection is null. If so, throw NullPointerException
java.util.Objects.requireNonNull(collection);
// Check if collection is empty. If so, throw Exception
if (collection.isEmpty()) {
throw new Exception("Collection is empty");
}
return collection;
}
}
Just as there is the method java.util.Objects.requireNonNull (..), it would be great if there is a similar method for collections that checks whether the collection is not null or empty.
Java pseudocode:
class java.util.Collections {
public static <T extends java.util.Collection<?>> T getNotEmpty( T collection) {
// Check if collection is null. If so, throw NullPointerException
java.util.Objects.requireNonNull(collection);
// Check if collection is empty. If so, throw Exception
if (collection.isEmpty()) {
throw new Exception("Collection is empty");
}
return collection;
}
}