requireNonNull

open fun <T> requireNonNull(@Nullable obj: @Nullable T): @NonNull T

Checks that the specified object reference is not null. This method is designed primarily for doing parameter validation in methods and constructors, as demonstrated below:

public Foo(Bar bar) {
    this.bar = ObjectsCompat.requireNonNull(bar);
}

Return

obj if not null

Parameters

obj

the object reference to check for nullity

<T>

the type of the reference

Throws


open fun <T> requireNonNull(@Nullable obj: @Nullable T, @NonNull message: @NonNull String): @NonNull T

Checks that the specified object reference is not null and throws a customized NullPointerException if it is. This method is designed primarily for doing parameter validation in methods and constructors with multiple parameters, as demonstrated below:

public Foo(Bar bar, Baz baz) {
    this.bar = ObjectsCompat.requireNonNull(bar, "bar must not be null");
    this.baz = ObjectsCompat.requireNonNull(baz, "baz must not be null");
}

Return

obj if not null

Parameters

obj

the object reference to check for nullity

message

detail message to be used in the event that a NullPointerException is thrown

<T>

the type of the reference

Throws