From the point of view of OO design, I would distinguish between two situations.
You want to model that nothing has been returned, the variable has not defined value. In this case I would use
null
. I cannot see any advantage of usingif (t == Type.NULL)
instead ofif (t == null)
.You want to model an empty operation/value has been returned, the variable is defined, but the value is a kind of a "zero". In that case I would use your solution, but I would not call it
NULL
, but ratherVOID
orEMPTY
or similar based on your business logic. This is preferable not because you want to useif (t == Type.NULL)
instead ofif (t == null)
, but because you want to not use any if at all - you may just use the variable as it contains a meaningful (however empty) value.