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
trueif you are comparing it tonullAs an instance of
NullObjectis not strictlynull, it returns false...Whether
NullObjectshould returntrueif you callequalsagainst anotherNullObjectis probably a question best asked on the mailing list... I'll have a look and see if I can find any previous question.