Java Assert Not Null assertNotNull(final T object, final String message)

Here you can find the source of assertNotNull(final T object, final String message)

Description

Checks if the given object is null.
If it is, a new NullPointerException is thrown with the given message.

License

Apache License

Parameter

Parameter Description
object - Object to check
message - Message for the NullPointerException

Return

The given object if it isn't null.

Declaration

public static <T> T assertNotNull(final T object, final String message) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from  ww w.  j a v a  2s  .  c o m
     * Checks if the given <code>object</code> is <code>null</code>.<br>
     * If it is, a new {@link NullPointerException} is thrown with the given message.
     * @param object - Object to check
     * @param message - Message for the {@link NullPointerException}
     * @return The given object if it isn't null.
     */
    public static <T> T assertNotNull(final T object, final String message) {
        if (object == null) {
            throw new NullPointerException(message);
        }
        return object;
    }
}

Related

  1. assertNotNull(final Object... objects)
  2. assertNotNull(final String message, final Object obj)
  3. assertNotNull(final String message, final Object object)
  4. assertNotNull(final String name, final T object)
  5. assertNotNull(final String param, final Object value)
  6. assertNotNull(final T value, final String param)
  7. assertNotNull(Object argumentThatMustNotBeNull, String argumentName)
  8. assertNotNull(Object expression)
  9. assertNotNull(Object o)