反射构造器注释参数二维数组长度判断
豆腐花发 2016-06-26 12:04:21 两个构造器:
public Practice(){
}
public Practice(
//注释参数类型
@Field_Method_Parameter_Annotation(describe = "人员编号", type = int.class)int id,
@Field_Method_Parameter_Annotation(describe = "人员姓名", type = String.class)String name){
this.id = id;
this.name = name;
}
获取构造器参数注释:
Annotation [][] cons_para_anno_arra = cons.getParameterAnnotations();
for(int j = 0; j < cons_para_anno_arra.length; j++){
int leng = cons_para_anno_arra[j].length;
if(leng == 0){
System.out.println("构造器没有参数");
}
else{
for(int k = 0; k < leng; k++){
Field_Method_Parameter_Annotation cons_para_anno = (Field_Method_Parameter_Annotation)cons_para_anno_arra[j][k];
System.out.println(cons_para_anno.describe() + " " + cons_para_anno.type());
}
}
}
System.out.println();
控制台显示:
---------构造器注释---------
人员编号 int
人员姓名 class java.lang.String
第一个构造器没有参数,为啥不显示“”构造器没有参数“?