现在的位置: 首页 > 综合 > 正文

反射机制补充

2014年08月26日 ⁄ 综合 ⁄ 共 7938字 ⁄ 字号 评论关闭
本篇文章为在工作中使用JAVA反射的经验总结,也可以说是一些小技巧,以后学会新的小技巧,会不断更新。

        在开始之前,我先定义一个测试类Student,代码如下:

  1. package chb.test.reflect;   
  2.   
  3. public class Student {   
  4.     private int age;   
  5.     private String name;   
  6.     public int getAge() {   
  7.         return age;   
  8.      }   
  9.     public void setAge(int age) {   
  10.         this.age = age;   
  11.      }   
  12.     public String getName() {   
  13.         return name;   
  14.      }   
  15.     public void setName(String name) {   
  16.         this.name = name;   
  17.      }   
  18.        
  19.     public static void hi(int age,String name){   
  20.          System.out.println("大家好,我叫"+name+",今年"+age+"岁");   
  21.      }   
  22. }

抱歉!评论已关闭.