Union{T,Nothing} vs multiple dispatch

Well, == is user-defined, so anything:

julia> struct MyType
         x::Int
       end

# This is probably a bad idea, but there's no reason you *can't* do it
julia> Base.:(==)(m::MyType, ::Nothing) = true

julia> MyType(1) == nothing
true

But === is always a test for actual equivalence, so even weird user code can’t override it:

julia> MyType(1) === nothing
false
2 Likes