Created
October 1, 2018 04:11
-
-
Save HeartSaVioR/f5d3f73455baed9bc22b66f9b16141a7 to your computer and use it in GitHub Desktop.
Tiny class to investigate why NoSuchMethodException occurs on your classpath
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
package net.heartsavior; | |
import java.lang.reflect.Constructor; | |
import java.lang.reflect.Field; | |
import java.lang.reflect.Method; | |
public class ClassInvestigator { | |
public static void main(String[] args) { | |
if (args.length < 1) { | |
System.out.println("USAGE: [class name]"); | |
System.exit(1); | |
} | |
String className = args[0]; | |
Class<?> clazz = null; | |
try { | |
clazz = Class.forName(className); | |
} catch (ClassNotFoundException e) { | |
System.err.println("Class not found! class name: " + className); | |
e.printStackTrace(System.err); | |
System.exit(2); | |
} | |
// constructors | |
System.out.println("================== CONSTRUCTORS ================="); | |
Constructor<?>[] constructors = clazz.getConstructors(); | |
for (Constructor cons : constructors) { | |
System.out.println(cons.toGenericString()); | |
} | |
// fields | |
System.out.println("================== FIELDS ================="); | |
Field[] fields = clazz.getFields(); | |
for (Field field : fields) { | |
System.out.println(field.toGenericString()); | |
} | |
// methods | |
System.out.println("================== METHODS ================="); | |
Method[] methods = clazz.getMethods(); | |
for (Method method : methods) { | |
System.out.println(method.toGenericString()); | |
} | |
System.out.println("DONE...."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment