How can I perform a reference equals in Groovy?
Use is
for testing object identity:
groovy:000> class Foo { }
===> true
groovy:000> f = new Foo()
===> Foo@64e464e4
groovy:000> g = new Foo()
===> Foo@47524752
groovy:000> f.is(g)
===> false
groovy:000> g.is(f)
===> false
groovy:000> f.is(f)
===> true
You use the is
method. ie:
a.is( b )
See the docs for more description
edit
Since groovy 3, you can use ===
(or !==
for the opposite)