集册 Java实例教程 打印类的方法

打印类的方法

欢马劈雪     最近更新时间:2020-01-02 10:19:05

468
打印类的方法
/**from 时代Java公众号 - N o w J a  v a . c o m**/


//package com.nowjava;


import java.lang.reflect.Method;


public class Main {

    public static void main(String[] argv) throws Exception {

        String clazz = "nowjava.com";

        printMethodsForClass(clazz);

    }


    public static void printMethodsForClass(final String clazz) {

        try {

            final Class<?> util = Class.forName(clazz);

            System.out.println("Methods for " + clazz);/**from 时   代     Java  公  众  号 - nowjava.com**/

            final Method[] methods = util.getMethods();

            for (final Method method : methods) {

                String sep = "";

                final StringBuilder buf = new StringBuilder();

                final Class<?>[] types = method.getParameterTypes();

                for (int i = 0, n = types.length; i < n; ++i) {

                    buf.append(sep);

                    buf.append(types[i].getName());

                    sep = ", ";

                }

            
展开阅读全文