如果在 kotlin 中指定了一些大小,如何将值设置为数据 class?

How to set values to data class if some size is specified in kotlin?

我在 kotlin 中有一个 data class 是这样的:

data class myDataClass(val myArr: ArrayList<Char>)

现在,假设我按如下方式创建它的一个实例:

val myData = myDataClass(x)    // x is an integer; 1 <= x <= 9

我希望 myData 应该有以下数据:

println(myData.myArr)
// [A, B, C, D, ...]

有可能:

data class myDataClass(val myArr: ArrayList<Char>) {
    constructor(i: Int) : this(ArrayList((0..i).map { ('A' + it).toChar() }))
}

但事实是,这是一个非常奇怪的代码