如何在Groovy中执行参考等于? [英] How can I perform a reference equals in Groovy?

查看:67
本文介绍了如何在Groovy中执行参考等于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Groovy将==映射到equals()通常很方便,但是当我想通过身份比较时该怎么办?例如,GPathResult通过调用text()来实现equals,对于大多数内部节点而言,该属性为空.我正在尝试确定根节点,但是使用该实现是不可能的.如果可以通过身份进行比较,那将是可能的.

It's often times convenient that Groovy maps == to equals() but what do I do when I want to compare by identity? For example, GPathResult implements equals by calling text(), which is empty for most internal nodes. I'm trying to identify the root node but with that implementation it's not possible. It would be possible if I could compare by identity.

推荐答案

您使用is方法.即:

a.is( b )

有关更多说明,请参见文档

See the docs for more description

从groovy 3开始,您可以使用 ===(或相反的是!==)

Since groovy 3, you can use === (or !== for the opposite)

这篇关于如何在Groovy中执行参考等于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆