5

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?

poke
  • 369,085
  • 72
  • 557
  • 602
scott
  • 1,557
  • 3
  • 15
  • 31

1 Answers1

3

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

nohup
  • 3,105
  • 3
  • 27
  • 52