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