public enum Weekday {
MON("星期一"), TUE("星期二"), WED("星期三"), THU("星期四"), FRI("星期五"), SAR("星期六"), SUN(
"星期天");
private Weekday(String day) {
this.day = day;
}
private String day;
public String getDay(){
return this.day;
}
public void setDay(String day) {
this.day = day;
}
}
==============================================================================
package DemoWeekday;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.Method;
import org.junit.Test;
public class WeekdayTest {
@Test
public void show() throws IntrospectionException {
// getDay(Weekday.FRI);
BeanInfo bi = Introspector.getBeanInfo(Weekday.class);
PropertyDescriptor[] pd = bi.getPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : pd) {
System.out.println(propertyDescriptor.getName());
}
}
@Test
public void show1() throws Exception {
PropertyDescriptor pd=new PropertyDescriptor("day", Weekday.class);
Method me=pd.getReadMethod();
System.out.println(me.invoke(Weekday.MON,null ));
}
public void getDay(Weekday WD) {
System.out.println(WD.getDay());
}
} |