git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lang] IllegalArgumentException factory methods


Hi All:

Similar to Objects.requireNonNull() but for IAEs:

/**
 * Factory methods for {@link IllegalArgumentException}.
 */
class IllegalArgumentExceptions {

    private static <T> T requireNonNull(T obj, String message, Object...
args) {
        if (obj == null) {
            throw new IllegalArgumentException(String.format(message,
args));
        }
        return obj;
    }

    public static <T> T requireNonNull(T obj) {
        return requireNonNull(obj, "Argument");
    }

    public static <T> T requireNonNull(T obj, String argumentName) {
        return requireNonNull(obj, "%s MUST not be null", argumentName);
    }

}

Suitable for [lang] I would think.

Thoughts?

Gary