摘要: import java.lang.annotation.Annotation; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Method; public class AnnotationTest { @Field_Method_Parameter_Annotation(describ="字段编号",type=int.class) //注释字段 int id; @Field_Method_Parameter_Annotation(describ="字段姓名",type=String.class)//注释字段 String name; @Constructor_Annotation()//采用默认构造方法 public AnnotationTest() { } @Constructor_Annotation("立即初始化构造方法.") //注释构造方法 public 阅读全文
posted @ 2010-09-01 14:15 叮当小马 阅读(8412) 评论(1) 推荐(1)
摘要: import java.lang.reflect.Field; public class FieldTest { int i; public float f; protected boolean b; private String s; public FieldTest() { i=0; f=0.0f; b = true; s = ""; } public static void main(String[] args){ //进行类实例化: FieldTest fieldTest = new FieldTest(); Field[] declaredFields = FieldTest.class.getDeclaredFields(); for(int i=0;ideclaredFields.length;i++){ Field field = declaredFields[i]; System.out.println("名称为:"+field.getName( 阅读全文
posted @ 2010-09-01 14:10 叮当小马 阅读(6200) 评论(0) 推荐(1)
摘要: import java.lang.reflect.Method; /** * @author Administrator * */ public class MethodTest { static void staticMethod() { System.out.println("执行staticMethod()方法"); } public int publicMethod(int i) { System.out.println("执行publicMethod()方法"); return i*20; } protected int protectedMethod(String s,int i) throws NumberFormatException{ System.out.println("执行protectedMethod()方法"); return Integer.valueOf(s)+i; } private String privateMethod(String...strings){ 阅读全文
posted @ 2010-09-01 14:04 叮当小马 阅读(6641) 评论(0) 推荐(1)
摘要: import java.lang.reflect.Constructor; //请注意执行顺序问题,开始时,我测试时用的是MyEclipse中的Jdk1.5.Jdk1.6我发现他们Constructor的顺序不一样的。 public class ReflectTest { String s; int i,i2,i3; protected ReflectTest() { s=""; i=0; i2=0; i3=0; } protected ReflectTest(String s,int i) { this.s = s; this.i = i; } public ReflectTest(String...strings) throws NumberFormatException //可变数量的参数 { if(0strings.length) { i = Integer.valueOf(strings[0]); } if(1strings.length) { 阅读全文
posted @ 2010-09-01 14:02 叮当小马 阅读(7784) 评论(0) 推荐(0)