Skip to content

Instantly share code, notes, and snippets.

@yarliganfatih
Created May 31, 2024 21:43
Show Gist options
  • Save yarliganfatih/1d9f5a7732e992f04e262add89965761 to your computer and use it in GitHub Desktop.
Save yarliganfatih/1d9f5a7732e992f04e262add89965761 to your computer and use it in GitHub Desktop.
print all methods, including inherited methods for testing
public class Main {
public static void printMethodNames(Class<?> clazz) {
// Get all methods of the class including inherited methods
Method[] methods = clazz.getMethods();
// Print method names and parameter types
for (Method method : methods) {
System.out.print(method.getName() + "(");
Class<?>[] parameterTypes = method.getParameterTypes();
for (int i = 0; i < parameterTypes.length; i++) {
System.out.print(parameterTypes[i].getSimpleName());
if (i < parameterTypes.length - 1) {
System.out.print(", ");
}
}
System.out.println(")");
}
}
public static void main(String[] args) {
Class<?> clazz = YourClass.class;
printMethodNames(clazz);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment