Is java equivalent to python "dir"?

Is there an equivalent to "dir" in python for java or a library that provides similar functionality (ie properties of objects and classes output as informative strings)?

This question is similar to this question for clojure and probably has something to do with Java Reflection, as in this question , which seems to be a more complex but similar topic.

+3
source share
2 answers

Nothing in the standard library that does exactly what it does dir(), but you can get the same information using java.lang.reflect. In particular, the study and discovery of class members is explained in the documentation for the detection of class members . Using this API, you can easily find out what you need to know about class attributes.

In fact, the implementation dir()itself would be a matter of defining a method that analyzes the methods and fields of the class and collects a collection of information or prints any information you would like to know.

dir() has limited utility in Java because Java is not interactive, but if you need it for educational / research purposes or for application logic, the reflection API is always present.

+4

, javap . : javap - The Java Class File Disassembler

javap java.lang.Double | grep -i int
public static final int MAX_EXPONENT;
public static final int MIN_EXPONENT;
public static final int SIZE;
public int intValue();
public int hashCode();
public int compareTo(java.lang.Double);
public static int compare(double, double);
public int compareTo(java.lang.Object);

System.out.println(),

javap -c java.lang.System | grep -i out
public static final java.io.PrintStream out;
public static void setOut(java.io.PrintStream);
   4: invokestatic  #4                  // Method setOut0:(Ljava/io/PrintStream;)V
   8: putstatic     #98                 // Field out:Ljava/io/PrintStream;

javap java.io.PrintStream

+2

All Articles