Nullable
Nullable(x)
Wrap value x
in an object of type Nullable
, which indicates whether a value is present. Nullable(x)
yields a non-empty wrapper, and Nullable{T}()
yields an empty instance of a wrapper that might contain a value of type T
.
Examples
-
Wrap a value in a Nullable object:
julia> nullable_value = Nullable(42) Nullable{Int64}(42)
This example wraps the value
42
in aNullable
object of typeInt64
. -
Create an empty Nullable object:
julia> nullable_empty = Nullable{Float64}() Nullable{Float64}()
This example creates an empty
Nullable
object of typeFloat64
that does not contain any value. - Check if a Nullable object is empty:
julia> nullable_value = Nullable("Julia") Nullable{String}("Julia") julia> isnull(nullable_value) false julia> nullable_empty = Nullable{Bool}() Nullable{Bool}() julia> isnull(nullable_empty) true
isnull
can be used to check if aNullable
object is empty or contains a value.
Common mistake example:
julia> nullable_value = Nullable()
ERROR: MethodError: no method matching Nullable()
In this example, the Nullable
function is called without providing a value or specifying a type. The correct usage is either Nullable(x)
to wrap a value or Nullable{T}()
to create an empty Nullable
object with a specified type.
See Also
BigFloat, BigInt, Dict, eltype, fieldtype, Float32, Float64, IntSet, isa, isalnum, isalpha, isascii, iseltype, isequal, isgraph, isimmutable, isinteractive, isleaftype, isnull, ispunct, isspace, issubtype, keytype, Nullable, NullException, promote_type, typeintersect, typejoin, typemax, typemin, typeof, Val, valtype,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.