Java equivalent of Python repr()?

后端 未结 9 1898
醉酒成梦
醉酒成梦 2020-12-18 18:18

Is there a Java method that works like Python\'s repr? For example, assuming the function were named repr,

\"foo\\n\\tbar\".repr()

would re

9条回答
  •  庸人自扰
    2020-12-18 18:56

    It appears that Jython already does this. You could, in theory, include the Jython jar, startup an interpreter, and actually run repr(object) on the object in question. Probably more overhead than you want, but does exactly what you describe.

    If you want to embed the Jython interpreter in your application, consider http://wiki.python.org/jython/JythonFaq/EmbeddingJython .

提交回复
热议问题