It's a hot topic now.
If you want a list of methods / fields in your program in Java, you can easily find it by using Java REPL. Of course, you can write it as a Java program, but use it when you want to check ** easily **.
In the following example, the method / field list of String class is displayed. Please replace it with the class name you want to check.
String class method list
java> String.class.getMethods()
String class method list
java> String.class.getFields()
getmethods
andgetfields
The method is a public method/Only fields are displayed. All methods including private etc./If you want to display the field, execute as follows.
List of all methods of String class
java> String.class.getDeclaredMethods()
List of all fields of String class
java> String.class.getDeclaredFields()
If you find it difficult to see at this rate, it will be a little longer, but please execute as follows.
List of all methods of String class (processed version)
java> Arrays.asList( String.class.getDeclaredMethods() ).forEach( System.out::println )
List of all fields of String class (processed version)
java> Arrays.asList( String.class.getDeclaredFields() ).forEach( System.out::println )
For classes that are not loaded by default in Java Repl, import them in advance or describe them with the package name included.
List of all methods of Color class (processed version)
java> Arrays.asList( java.awt.Color.class.getDeclaredMethods() ).forEach( System.out::println )
As mentioned above, it was a topic that was delayed by about 5 to 10 years.
Java: How to output a list of names and values of all fields in a class
Field acquisition with Java reflection API
Recommended Posts