Groovy对象id

Groovy对象id,groovy,Groovy,我有一个基本的常规问题 当我打印groovy对象时,它看起来是这样的: groovy:000> f = new Foo() ===> Foo@60410cd 给定groovy对象,如何获得对象id部分Foo@60410cd是使用java.lang.Object 按照JavaDoc中的定义,默认的toString()将返回: getClass().getName() + '@' + Integer.toHexString(hashCode()) 如您所见,它使用hashCode()

我有一个基本的常规问题

当我打印groovy对象时,它看起来是这样的:

groovy:000> f = new Foo()
===> Foo@60410cd

给定groovy对象,如何获得对象id部分Foo@60410cd是使用
java.lang.Object

按照JavaDoc中的定义,默认的
toString()
将返回:

getClass().getName() + '@' + Integer.toHexString(hashCode())
如您所见,它使用
hashCode()
方法的值跟踪结果。默认的
hasCode()
返回:

不同对象的不同整数。(这通常通过将对象的内部地址转换为整数来实现,但JavaTM编程语言不需要这种实现技术。)

因此,您看到的是对
Object.toString()
Object.hashCode()的默认调用的结果

如果要更改输出,应重写默认的
toString()
方法,类似于:

String toString(){
    "In Foo!"
}

您的用例是什么?
Foo f = new Foo()

Integer.toHexString(System.identityHashCode(f))​​​​​​​​​​​​​​​​​​​​​​​