寻找标准库或技术以获得漂亮的Java OBJECT表示形式 [英] Looking for standard library or technique to get pretty-printed representation of OBJECT for Java
问题描述
为了了解某些代码的内部结构或因错误而打印转储,我在
In order to understand internals of some code or print dumps on errors I use pp-like functions in Python and Emacs lisp.
现在,我进入Java并寻找标准库或技术以获取漂亮的OBJECT for Java表示.
Now I come to to Java and look for standard library or tecnique to get pretty-printed representation of OBJECT for Java.
似乎当前的Java规范允许在运行时对Java对象进行自省.但是内省可能没有那么强大. m(对象o)不能用新对象[] arg调用吗?
Seems that current Java specification allow introspection of Java object at runtime. But introspection may be not so powerful. m(Object o) can not be called with new Object [] arg?
注意,我不正在寻找美化源代码的方法!我正在寻找运行时漂亮的打印Java对象转储.
NOTE I am NOT looking to source code beautifier! I am looking for runtime pretty print Java object dumping.
NOTE2 这些问题相似但不完全相同:
NOTE2 These questions similar but not exactly same:
推荐答案
您可以使用 Apache Commons Lang 库.
示例:
String dump = ReflectionToStringBuilder.toString(object);
关于您的问题:
m(Object o)不能用新的Object [] arg调用吗?
m(Object o) can not be called with new Object [] arg?
当然可以, Object
的数组是 Object
的子类型.
Sure it can, arrays of Object
is a subtype of Object
.
这篇关于寻找标准库或技术以获得漂亮的Java OBJECT表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!