成员方法(类的反射)

来源:互联网 发布:淘宝运费价格表监控 编辑:程序博客网 时间:2024/05/29 19:46
package lei;import java.lang.reflect.Method;/** * 成员方法都是Method类的对象 * 类的反射 * @author Administrator * */public class MethodName {    @SuppressWarnings("rawtypes")    public static void main(String[] args) throws ClassNotFoundException {        Class c=Class.forName("lei.MethodName");//动态加载//      Method[] m=c.getMethods();//动态加载进来该类所有公开的方法以及集成父类的方法        Method[] m=c.getDeclaredMethods();//获得该类自身所有的方法        for (Method method : m) {            Class creturn=method.getReturnType();            System.out.print(creturn.getSimpleName()+" ");//获取方法返回值类型名称            String methodName=method.getName();            System.out.print(methodName+"(");//获取方法名            Class[] para=method.getParameterTypes();//获取参数列表            for (Class c1 : para) {                System.out.print(c1.getSimpleName()+",");            }            System.out.println(")");        }    }    public void aaa(){    }    protected void bbb(){    }    @SuppressWarnings("unused")    private void ccc(){    }    void ddd(){    }}
0 0
原创粉丝点击