ReflectObject.java
资源名称:Appjxc.rar [点击查看]
上传用户:whbcdz
上传日期:2008-08-04
资源大小:7683k
文件大小:2k
源码类别:
JavaScript
开发平台:
Java
- package appjxc.constrol;
- import appjxc.model.Obj_gys;
- import java.lang.reflect.*;
- public class ReflectObject {
- static Obj_gys objgys = new Obj_gys();
- public static void printMethods(Class c1){
- System.out.println("class " + c1.getName());
- Method[] method = c1.getDeclaredMethods();
- for(int i = 0 ; i < method.length ; i++){
- Method m = method[i];
- Class retype = m.getReturnType();
- String name = m.getName();
- System.out.print(Modifier.toString(m.getModifiers()));
- System.out.print(" " + retype.getName() + " " + name +"(");
- Class[] param = m.getParameterTypes();
- for(int j = 0 ; j < param.length ; j++){
- if(j > 0) System.out.print(",");
- System.out.print(param[j].getName());
- }
- System.out.println(")");
- }
- }
- public static void printFields(Class c1){
- Field[] fields = c1.getDeclaredFields();
- for(int i = 0 ; i < fields.length ; i++){
- Field f = fields[i];
- Class type = f.getType();
- String name = f.getName();
- try{
- String mm = f.get(objgys).toString();
- System.out.println(mm);
- }catch(java.lang.IllegalAccessException ill){
- ill.printStackTrace();
- }
- System.out.print(Modifier.toString(f.getModifiers()));
- System.out.println(" " + type.getName() + " " + name + ";");
- }
- }
- public static void main(String[] args) {
- ReflectObject reflectobject = new ReflectObject();
- objgys.setGysbh("001");
- objgys.setGysmc("长春制药厂");
- objgys.setGysdz("长春市高薪区25号");
- objgys.setPym("CC");
- objgys.setSsdq("吉林省长春市");
- objgys.setTel("0431-8545236");
- objgys.setLxr("吕海涛");
- objgys.setKhyh("交通银行");
- objgys.setKhzh("60142820358820808");
- printMethods(objgys.getClass());
- printFields(objgys.getClass());
- }
- }