Validates if the given objects is not null. - Android java.lang

Android examples for java.lang:Throwable

Description

Validates if the given objects is not null.

Demo Code


//package com.java2s;

public class Main {
    /**/*from  w  w  w  . j a  v a  2  s.com*/
     * Validates if the given objects is not null. If it is not, throws an
     * {@link IllegalArgumentException} with the given message.
     * 
     * @param value
     *            The value to be checked.
     * @param message
     *            The message of the exception.
     */
    public static void notNull(Object value, String message) {
        if (value == null) {
            throw new IllegalArgumentException(message);
        }
    }

    /**
     * Validates if the given objects is not null. If it is not, throws an
     * {@link IllegalArgumentException}.
     * 
     * @param value
     *            The value to be checked.
     */
    public static void notNull(Object value) {
        notNull(value, "Null value!");
    }
}

Related Tutorials