Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the alternate of python's dir() in Java? [duplicate]

While learning java through an online course, I came across type conversions using helper classes. Eg:

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

However they doesn't explain how can I find the methods like do.intvalue() if I am unaware of the existing methods. In Python, I can do a dir(do) and it would list all the methods. How can I check the same in Java?

like image 242
scott Avatar asked Oct 19 '22 23:10

scott


1 Answers

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 eg. If you see System.out.println(), but wondering what else could 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

like image 161
nohup Avatar answered Oct 22 '22 10:10

nohup