Check for 'null' values
This static utility allows you to check for any arbitrary number of values, ensuring none of them are null.
/**
 * Validates that all values are set.
 *
 * @param values a varargs array of arguments
 */
public static void defenseNotNull(Object... values) {
    if (values == null) {
        throw new IllegalArgumentException("values is null");
    }
    for (int i = 0; i < values.length; i++) {
        Object value = values[i];
        if (value == null) {
            throw new IllegalArgumentException(String.format("values[%d] is null", i));
        }
    }
}Use as:
defenseNotNull(a, b, c, ...);Written by Raúl Raja
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Utilities 
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
 
