java 反射初探

getDeclaredMethods与getMethods的区别
package com.cz.jl.excel;

import java.beans.PropertyDescriptor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import javax.management.IntrospectionException;

import com.hib.model.Ctlm1007;

public class Flct<T> 
{
	public static void main(String[] args) {
		Flct f = new Flct();
		Ctlm1007 obj = new Ctlm1007();
		f.method(obj);
	}
	public static void method(Object obj) {
			Class clazz = obj.getClass();
			System.out.println("clazz"+clazz);
			Field[] fields = obj.getClass().getDeclaredFields();//获得属性
			//当前类用户声明的方法
			Method[] m = obj.getClass().getDeclaredMethods();
			for (Method method : m) {
				method.setAccessible(true);
				System.out.println(method.getName());
			}
	}
	public static void methods(Object obj) {
			Class clazz = obj.getClass();
			System.out.println("clazz"+clazz);
			Field[] fields = obj.getClass().getDeclaredFields();//获得属性
			//所有方法,包含该类继承的wait....等
			Method[] m = obj.getClass().getDeclaredMethods();
			for (Method method : m) {
				method.setAccessible(true);
				System.out.println(method.getName());
			}
	}
}
 
 

猜你喜欢

转载自blog.csdn.net/u012717420/article/details/24694265