我有一个名为PaymentFrequency的枚举:
public enum PaymentFrequency {
D("Daily"),
W("Weekly"),
M("Monthly"),
Y("Yearly");
private final String description;
PaymentFrequency(final String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
现在,如果我在我的bean中这样做:
private PaymentFrequency[] paymentPeriods = PaymentFrequency.values();
public PaymentFrequency[] getPaymentPeriods() {
return paymentPeriods;
}
public void setPaymentPeriods(PaymentFrequency[] paymentPeriods) {
this.paymentPeriods = paymentPeriods;
}
我将从枚举中获取所有值。如何只获取值 W 和 M ?
答案 0 :(得分:1)
您可以添加数组
static final PaymentFrequency[] WM = { W, M };
答案 1 :(得分:1)
嗯,你可以做到
private PaymentFrequency[] paymentPeriods =
new PaymentFrequency[] {PaymentFrequency.W, PaymentFrequency.M};
答案 2 :(得分:0)
private PaymentFrequency[] paymentPeriods = new PaymentFrequency[] {PaymentFrequency.W, PaymentFrequency.M};
我不确定这是不是你的问题......