寻找标准库或技术来获得漂亮的Java OBJECT表示形式 [英] Look for standard library or technique to get pretty-printed representation of OBJECT for Java

查看:68
本文介绍了寻找标准库或技术来获得漂亮的Java OBJECT表示形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了理解某些代码的内部结构或因错误而打印转储,我在pp 的函数 rel = nofollow noreferrer> Python 和Emacs lisp。

In order to understand internals of some code or print dumps on errors I use pp-like functions in Python and Emacs lisp.

现在,我来到Java,寻找标准库或tecnique以获得漂亮的印刷品

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:

  • What's the simplest way to print a Java array?
  • Best pretty-printing library for Java?
  • Java dump an object

推荐答案

您可以使用 Apache Commons Lang 库中的ReflectionToStringBuilder

You could use the ReflectionToStringBuilder from the Apache Commons Lang library.

示例:

String dump = ReflectionToStringBuilder.toString(object);

关于您的问题:


m(Object o)不能用新对象[] arg调用吗?

m(Object o) can not be called with new Object [] arg?

当然可以,数组对象的子类型是对象的子类型。

Sure it can, arrays of Object is a subtype of Object.

这篇关于寻找标准库或技术来获得漂亮的Java OBJECT表示形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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