In class constructor you need to add varval. It will create field automatic. Or make it by yourself.
class Foo(vararg val params: String) {
fun toString(): String = params.fold("Args:") { a, b -> "$a $b" }
}
class Bar(vararg params: String) {
val args = params
fun toString(): String = args.fold(“Args:”) { a, b -> “$a $b” }
}
fun main(args : Array<String>) {
println(Foo(“First”,“Second”, “Last”)) // Args: First Second Last
println(Bar(“First”,“Second”, “Last”)) // Args: First Second Last
}