首页 > 学院 > 开发设计 > 正文

成员方法(类的反射)

2019-11-11 05:09:16
字体:
来源:转载
供稿:网友
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(){ }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表