Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns the public static methods of a class or interface,
- * including those declared in super classes and interfaces.
- */
- public static List<Method> getStaticMethods(Class<?> clazz) {
- List<Method> methods = new ArrayList<Method>();
- for (Method method : clazz.getMethods()) {
- if (Modifier.isStatic(method.getModifiers())) {
- methods.add(method);
- }
- }
- return Collections.unmodifiableList(methods);
- }
- for (Method m : MyClass.class.getMethods()) {
- if (Modifier.isStatic(m.getModifiers()))
- System.out.println("Static Method: " + m.getName());
- }
- public Method[] getStatics(Class<?> c) {
- Method[] all = c.getDeclaredMethods()
- List<Method> back = new ArrayList<Method>();
- for (Method m : all) {
- if (Modifier.isStatic(m.getModifiers())) {
- back.add(m);
- }
- }
- return back.toArray(new Method[back.size()]);
- }
Add Comment
Please, Sign In to add comment