Scala 中的 var_dump()
有没有方便的方法来转储 Scala 中指定对象的所有成员,
像var_dump()
,PHP函数?
Is there any convenient way to dump all members of a specified object in Scala,
like var_dump()
, PHP function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如“如何转储/检查对象或Java中的变量”(是的,我知道,问题是关于Scala的):
但是如果您想要更多详细信息,您可以提供 REPL Scala Utils 尝试一下,以获得“Scala REPL 中的对象检查更容易"
(注:“我”在这里:Erik Engbrecht,还有< a href="https://bitbucket.org/eengbrec" rel="noreferrer">BitBucket)
As mentioned in "How to Dump/Inspect Object or Variable in Java" (yes, I know, the question is about Scala):
But if you want more details, you can give REPL Scala Utils a try, in order to get a "Easier object inspection in the Scala REPL"
(Note: "I" being here: Erik Engbrecht, also on BitBucket)
您可能想查看 ToStringBuilder 在 commons-lang 中,特别是
ToStringBuilder.reflectionToString()
。You might want to look at ToStringBuilder in commons-lang, specificly
ToStringBuilder.reflectionToString()
.在编译的代码中,最好的方法通常是将您的类型声明为案例类,然后使用生成的 toString 方法。
任何其他子类
Product
都应该同样简单(目前只是元组)如果做不到这一点,请编写自己的
toString
方法,它通常很简单......In compiled code, the nicest way is usually just to declare your type as a case class, then use the generated
toString
method.Anything else subclassing
Product
should be just as easy (currently just tuples)Failing that, write your own
toString
method, it's usually trivial enough...