标签:java 使用 io ar text return c public
定义枚举
public enum YesOrNo {
YES("是") ,
NO("否") ;
private String text ;
private int code ;
YesOrNo(){
this.text = this.name() ;
this.code = this.ordinal() ;
}
YesOrNo(String text){
this.text = text ;
this.code = this.ordinal() ;
}
YesOrNo(String text,int code){
this.text = text ;
this.code = code ;
}
public String getText() {
return text;
}
public int getCode() {
return code;
}
}public static void main(String[] args) throws Exception{
Method method = MethodUtils.getAccessibleMethod(YesOrNo.class , "getText") ;
Method method1 = MethodUtils.getAccessibleMethod(YesOrNo.class , "getCode") ; // 使用类反射
System.out.println( method.invoke( YesOrNo.YES ) ) ;
System.out.println( method1.invoke( YesOrNo.NO ) ) ;
System.out.println( YesOrNo.YES.getText() );
}标签:java 使用 io ar text return c public
原文地址:http://blog.csdn.net/hfmbook/article/details/38320493