This example can be easily tested in the groovy console.
var a is evaluated to not null while b is evaluated to null.
Both are instances of org.codehaus.groovy.runtim.NullObject
def b = null
println b.getClass()
println b == null
def a = null.getClass().newInstance()
println a.getClass()
println a == null
Does anyone knows why?
This is a tricky thing when dealing with reflection code.
In the equals method of NullObject, it only returns
true
if you are comparing it tonull
As an instance of
NullObject
is not strictlynull
, it returns false...Whether
NullObject
should returntrue
if you callequals
against anotherNullObject
is probably a question best asked on the mailing list... I'll have a look and see if I can find any previous question.