/*
Method getMethod(String name,Class[] params) --使用指定的参数类型获得由name参数指定的public类型的方法。
Mehtod[] getMethods()获得一个类的所有的public类型的方法
Mehtod getDeclaredMethod(String name, Class[] params)使用指定的参数类型获得由name参数所指定的由这个类声明的方法。
Method[] getDeclaredMethods() 获得这个类所声明的所有的方法
Constructor getConstructor(Class[] params) 使用指定的参数类型来获得公共的构造器;
Constructor[] getConstructors() 获得这个类的所有构造器;
Constructor getDeclaredConstructor(Class[] params) 使用指定的参数类型来获得构造器(忽略访问的级别)
Constructor[] getDeclaredConstructors() 获得这个类的所有的构造器(忽略访问的级别)
*/
//用类反射处理:
//例如我们要遍历一个名叫customer的类,那么我们写一个遍历这个类的函数
public static Object test(Class type) throws Exception
{
Method[] method = type.getDeclaredMethods();//取得该类的所有方法
for (int i = 0; i < method.length; i++)
{
Method s_method = method[i];
String method_name = s_method.getName();//取得该方法的名
if (method_name.length() >=3 && method_name.substring(0,3).equals("get"))//如果该方法名以get开头
{
Object get_value = s_method.invoke(type.newInstance(), null);//运行该方法,其中后面一个参数null是需要传进该方法的参数,是Object[]类型的,运行该方法后返回的也是Object类型,如果你需要返回字符串类型,可以再进行转换
}
}
}