打印出 Groovy 对象中的变量和值 [英] Printing out variables and values in a Groovy object
本文介绍了打印出 Groovy 对象中的变量和值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何打印出 Groovy 对象的(公共和内部)变量及其值?
How can I print out the (public and internal) variables and their values of a Groovy object?
即
class X
{
def X = 10
def Y = 5
private void doPrivate()
{
def Z = 3
}
}
应该给
X, 10
Y, 5
Z, 3
这必须是一个动态解决方案,即在运行时.
This has to be a dynamic solution, i.e at runtime.
推荐答案
dump()
例如
println "ddd".dump()
打印:
java.lang.String@2ef900 value=dddd offset=0 count=4 hash=3078400
java.lang.String@2ef900 value=dddd offset=0 count=4 hash=3078400
这篇关于打印出 Groovy 对象中的变量和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文