0

我有一个名为 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;
}

我将从我的枚举中获得所有值。我怎样才能只得到值WM

4

3 回答 3

1

您可以添加一个数组

static final PaymentFrequency[] WM = { W, M };
于 2012-07-31T07:48:54.353 回答
1

好吧,你可以做

 private PaymentFrequency[] paymentPeriods = 
     new PaymentFrequency[] {PaymentFrequency.W, PaymentFrequency.M};
于 2012-07-31T07:49:54.967 回答
0
private PaymentFrequency[] paymentPeriods = new PaymentFrequency[] {PaymentFrequency.W, PaymentFrequency.M};

我不确定这是否是你的问题......

于 2012-07-31T07:51:43.580 回答