Ask Learn
Preview
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign inThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
RequireNonNull(Object) |
Checks that the specified object reference is not |
RequireNonNull(Object, ISupplier) |
Checks that the specified object reference is not |
RequireNonNull(Object, String) |
Checks that the specified object reference is not |
Checks that the specified object reference is not null
.
[Android.Runtime.Register("requireNonNull", "(Ljava/lang/Object;)Ljava/lang/Object;", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static Java.Lang.Object RequireNonNull(Java.Lang.Object? obj);
[<Android.Runtime.Register("requireNonNull", "(Ljava/lang/Object;)Ljava/lang/Object;", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member RequireNonNull : Java.Lang.Object -> Java.Lang.Object
the object reference to check for nullity
obj
if not null
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: <blockquote>
public Foo(Bar bar) {
this.bar = Objects.requireNonNull(bar);
}
</blockquote>
Java documentation for java.util.Objects.requireNonNull(T)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Checks that the specified object reference is not null
and
throws a customized NullPointerException
if it is.
[Android.Runtime.Register("requireNonNull", "(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;", "", ApiSince=24)]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static Java.Lang.Object RequireNonNull(Java.Lang.Object? obj, Java.Util.Functions.ISupplier messageSupplier);
[<Android.Runtime.Register("requireNonNull", "(Ljava/lang/Object;Ljava/util/function/Supplier;)Ljava/lang/Object;", "", ApiSince=24)>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member RequireNonNull : Java.Lang.Object * Java.Util.Functions.ISupplier -> Java.Lang.Object
the object reference to check for nullity
supplier of the detail message to be
used in the event that a NullPointerException
is thrown
obj
if not null
Checks that the specified object reference is not null
and throws a customized NullPointerException
if it is.
Unlike the method #requireNonNull(Object, String)
, this method allows creation of the message to be deferred until after the null check is made. While this may confer a performance advantage in the non-null case, when deciding to call this method care should be taken that the costs of creating the message supplier are less than the cost of just creating the string message directly.
Added in 1.8.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Checks that the specified object reference is not null
and
throws a customized NullPointerException
if it is.
[Android.Runtime.Register("requireNonNull", "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", "")]
[Java.Interop.JavaTypeParameters(new System.String[] { "T" })]
public static Java.Lang.Object RequireNonNull(Java.Lang.Object? obj, string message);
[<Android.Runtime.Register("requireNonNull", "(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;", "")>]
[<Java.Interop.JavaTypeParameters(new System.String[] { "T" })>]
static member RequireNonNull : Java.Lang.Object * string -> Java.Lang.Object
the object reference to check for nullity
detail message to be used in the event that a NullPointerException
is thrown
obj
if not null
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: <blockquote>
public Foo(Bar bar, Baz baz) {
this.bar = Objects.requireNonNull(bar, "bar must not be null");
this.baz = Objects.requireNonNull(baz, "baz must not be null");
}
</blockquote>
Java documentation for java.util.Objects.requireNonNull(T, java.lang.String)
.
Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.
Ask Learn is an AI assistant that can answer questions, clarify concepts, and define terms using trusted Microsoft documentation.
Please sign in to use Ask Learn.
Sign in