Java examples for Reflection:Method
print Methods
//package com.java2s; import java.lang.reflect.*; import static java.lang.System.out; public class Main { public static void printMethods(Class<?> c) { out.format("Methods => %n"); Method[] methods = c.getDeclaredMethods(); if (methods.length == 0) { out.format(" --%s", "No declared method found"); } else {//from w w w.j a v a 2 s. c o m for (Method m : methods) { Parameter[] params = m.getParameters(); StringBuffer sb = new StringBuffer(); if (params.length != 0) { int i = 0; for (; i < params.length - 1; i++) { sb.append(params[i].getType().getCanonicalName() + " " + params[i].getName()); sb.append(", "); } sb.append(params[i].getType().getCanonicalName() + " " + params[i].getName()); } out.format(" %s %s %s(%s)%n", Modifier.toString(m .getModifiers()), m.getReturnType() .getCanonicalName(), m.getName(), sb.toString()); } } } }