Created
May 31, 2024 21:43
-
-
Save yarliganfatih/1d9f5a7732e992f04e262add89965761 to your computer and use it in GitHub Desktop.
print all methods, including inherited methods for testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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