So, to avoid ubiquitous
Well, in principle, theoretically speaking, we could invent class methods that would be called when the instance is null. But we are told that class info is carried around in instances only.
Really? Is Java compiler so dumb that it does not know the type of expression when the result is null, even if the type is explicitly declared? I got a feeling that we already have a null object for all Java classes, and all that we need is the ability to provide that object with type-dependent functionality.
if(x == null)
in Java, we are told to use Null Object Pattern and create a special Null object for each class we are dealing with. For instance, a database returns null instead of expected Timestamp - it is not a big deal, but we will need a Timestamp.NULL
object to handle the "problem". The other problem is that Timestamp does not have any Null Object, and subclassing it to have one would break tons of code.Well, in principle, theoretically speaking, we could invent class methods that would be called when the instance is null. But we are told that class info is carried around in instances only.
Really? Is Java compiler so dumb that it does not know the type of expression when the result is null, even if the type is explicitly declared? I got a feeling that we already have a null object for all Java classes, and all that we need is the ability to provide that object with type-dependent functionality.