What is the alternative to python dir () in Java?

When learning Java through an online course, I came across type conversions using helper classes. For example:

double d = 5.99;
double do = new Double(d);
int i = do.intvalue();

However, they do not explain how to find methods similar do.intvalue()if I do not know the existing methods. In Python, I can do dir(do)and it will list all the methods. How can I test this in Java?

+4
source share
1 answer

You can use javap for the same.

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);

For example, if you see System.out.println(), but are wondering what else might be available, you can always check

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;

and then do javap java.io.PrintStream

+2
source

Source: https://habr.com/ru/post/1613607/


All Articles