Java相当于python的“dir”?
java中的python中是否有相当于“dir”的东西,或者提供类似功能的库(即对象和类的属性输出为信息字符串)?
这个问题与 clojure 的 问题 类似,并且可能与 Java Reflection 有关在这个问题中,这似乎是关于更复杂但相似的主题。
Is there an equivalent to "dir" in python for java, or a library which provides similar functionality (i.e. properties of objects and classes output as informative strings)?
This question is similar this question for clojure and probably has something to do with Java Reflection as in this question, which seems to be about a more complicated, but similar, topic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准库中没有任何内容可以完全完成
dir()
的功能,但您可以使用java.lang.reflect
获得相同的信息。具体来说,有关发现类的文档中解释了调查和发现类的成员成员。使用该 API,您可以轻松找到您需要了解的有关类属性的信息。事实上,自己实现 dir() 只需定义一个方法,该方法可以内省类的方法和字段,然后组装信息集合或打印您想要的任何信息。知道。
dir()
在 Java 中的用处有限,因为 Java 不是交互式的,但如果您需要它用于教育/调查目的或应用程序逻辑,反射 API 总是存在的。There's nothing in the standard library that accomplishes exactly what
dir()
does, but you can get the same information usingjava.lang.reflect
. Specifically, investigating and discovering members of a class is explained in the documentation on discovering class members. Using that API you can easily find out what you need to know about the attributes of a class.In fact, implementing
dir()
yourself would just be a matter of defining a method that introspects the methods and fields of a class and either assembles a collection of the info or prints whatever information you'd like to know.dir()
has limited usefulness in Java because Java is not interactive, but if you need it for educational/investigative purposes or for application logic, the reflection API is always there.我在想使用 javap 是否是一个不错的选择。那人说
javap - Java 类文件反汇编器
来查看内置方法
,我可以通过使用 System.out.println()
,然后执行 javap java.io。打印流
I was thinking if using javap would be a good choice. The man says
javap - The Java Class File Disassembler
and I could see the built in methods by
Taking
System.out.println()
,and then do
javap java.io.PrintStream