public abstract class Nulls extends Object
Modifier and Type | Method and Description |
---|---|
static <T> T[] |
arrayOk(T[] a)
This is designed to "cast" an array of
Nullable
values to an array of NonNull values. |
static <T> T |
ok(T v)
This is designed to "cast" a
Nullable value
to a NonNull one in contexts where the type is
not strong enough but the programmer is sure enough (e.g. |
public static <T> T ok(T v)
Nullable
value
to a NonNull
one in contexts where the type is
not strong enough but the programmer is sure enough (e.g.
a call to Map.get(java.lang.Object)
after a check with Map.containsKey(java.lang.Object)
).
It checks the input for null
anyway and the case
being throws an NullPointerException
, acting as
a dynamically-checked cast.
It is advised that every call to this method be justified
with some suitable comment.
v
- v
making sure it is non-nullNullPointerException
- if v
is nullpublic static <T> T[] arrayOk(T[] a)
Nullable
values to an array of NonNull
values. It is necessary
because except in the case of array initializers, it is often
not possible to initialize all the cells in an array at once,
and thus impossible to declare them as containing non-null values
from the start. This method can be used once all cells are known
to have been initialized to non-null values. It does not perform
any dynamic checks and therefore is potentially type unsafe.
It is advised that every call to this method be justified
with some suitable comment.
a
- a
with a stronger type without run-time checks