- /*
- 此方法通过反射获得一个类的所有方法 包括参数
- */
- public class Text01{
- public static void main(String[] args) {
- Method[] methods = String.class.getMethods();
- for (Method method : methods) {
- String name = method.getName();
- StringBuilder stringBuilder = new StringBuilder(name);
- stringBuilder.append('(');
- Class[] clazzParams = method.getParameterTypes();//此步获得方法的参数
- for (Class clazzParam : clazzParams) {
- stringBuilder.append(clazzParam.getName()).append(',');
- }
- if (clazzParams != null && clazzParams.length != 0)
- stringBuilder.deleteCharAt(stringBuilder.length()-1);
- stringBuilder.append(')');
-
- System.out.println(stringBuilder.toString());
- }
-
- }
- }
复制代码 |