如何通过setter和getter存储和传递CharSequence?

时间:2018-03-03 06:14:16

标签: java charsequence

我有一个DepositTypes类,其中CharSequence数组作为参数。我使用了CharSequence depositPeriod[]的setter和getter。在generatePeriod()中,我必须为depositPeriod[]类的每个项目生成一些随机数并将其保存到DepositTypes

在我的MainActitvity课程中,我需要检索depositPeriod final CharSequence charSequence[] = deposit_types.get(positionOfDeposit).getDepositPeriod();。当我检查charSequence的值时,我得到了 [Ljava.lang.CharSequence;@bd8aa05

问题如何从DepositTypes班级获取CharSequence并在MainActivity中使用

class DepositTypes {
    ...
    private CharSequence depositPeriod[];

private DepositTypes(..., ...,  CharSequence depositPeriod[]) {
    ...
    setDepositPeriod(depositPeriod);
}
   ... ...

public CharSequence[] getDepositPeriod() {
    return depositPeriod;
}

public void setDepositPeriod(CharSequence[] depositPeriod) {
    this.depositPeriod = depositPeriod;
}

static List<DepositTypes> generateDepositTypes(Context context) {
    ArrayList<DepositTypes> deposits = new ArrayList<>();
     ...
     ...

    Random rand = new Random();


    for (int i = -1; i < deposit_types.length; i++) {
        if (i != -1) {
           CharSequence[] depositPeriod = generatePeriod();     
           deposits.add(new DepositTypes(..., ..., depositPeriod));
        } else {
            ...
            ...
        }
    }
    return deposits;
}
static CharSequence[] generatePeriod() {
    Random rand = new Random();
    int period = rand.nextInt(3) + 3;
    CharSequence[] depositPeriod = new String[period];

    for (int i = 0; i < period; i++) {
        int days = rand.nextInt(335) + 31;
        depositPeriod[i] = String.valueOf(days);
        Log.v("AAA", "in Class -> " + depositPeriod[i]);
    }

    return depositPeriod;
}

}

0 个答案:

没有答案