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());
}
}
}