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