Easy way to check method / field list in Java REPL

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 **.

Method / field list

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

List of all methods / fields

getmethodsandgetfieldsThe 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()

List of all methods / fields (processed version)

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

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 )

in conclusion

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

Easy way to check method / field list in Java REPL
[Rails] Easy way to check columns
Change List <Optional <T >> to Optional <List <T >> in Java
[Java] Is it unnecessary to check "identity" in the implementation of the equals () method?
[java] sort in list
Sample code to convert List to List <String> in Java Stream
How to get the class name / method name running in Java
[Android, Java] Convenient method to calculate the difference in days
Create a method to return the tax rate in Java
Check https connection in Java
List aggregation in Java (Collectors.groupingBy)
Easy to use array.map (&: method)
[Java] I want to check that the elements in the list are null or empty [Collection Utils]
[Java] How to search for a value in an array (or list) with the contains method
A clever way to unify loggers to SLF4J in Java / build.gradle entry / 2019
Cast an array of Strings to a List of Integers in Java
An easy way to cache method calls with Ruby's native extensions
Multithreaded to fit in [Java] template
Automatic photo resizing method in Java
Java method list (memorial) (under construction)
[Java] How to use join method
[Java] Object-oriented syntax-class / field / method / scope
How to learn JAVA in 7 days
Log output to file in Java
[Java] Convert 1-to-N List to Map
List of members added in Java 9
Check Java parameters in Kubernetes pods
Try to extract java public method
[Java] How to use List [ArrayList]
How to use classes in Java?
How to name variables in Java
Try to implement Yubaba in Java
List of types added in Java 9
[Java] Conversion from array to List
How to concatenate strings in java
Call the super method in Java
[Java] Pass arguments to constructor in Mockito / Set method default call to callRealMethod
How to test a private method in Java and partially mock that method
Use static initialization block to initialize List / Set of static fields in Java
How to get Excel sheet name list in Java (POI vs SAX)
How to check Java installed on Mac
How to implement date calculation in Java
How to implement Kalman filter in Java
Multilingual Locale in Java How to use Locale
Java reference to understand in the figure
[Java] How to compare with equals method
Easy way to set iOS app icon
Try to implement n-ary addition in Java
Call Java method from JavaScript executed in Java
Understand java interface in your own way
[Java] How to add data to List (add, addAll)
Concurrency Method in Java with basic example
How to use submit method (Java Silver)
How to do base conversion in Java
[Java] How to use the toString () method
How to have params in link_to method
Convert SVG files to PNG files in Java
How to implement coding conventions in Java
What is the main method in Java?
How to embed Janus Graph in Java
Immutable (immutable) List object conversion function in Java8