commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Gregory <garydgreg...@gmail.com>
Subject [lang] IllegalArgumentException factory methods
Date Sun, 07 Oct 2018 16:13:15 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message