data class have one property visibility modifier is private and delegated by price. why it not print [100,200,300,400]$.
data class Container(val food: String, private val prices: MutableList) : MutableList by prices
var (food , prices) = Container(“chicken”, mutableListOf(100,200,300,400))
println( “Food: $food and Prices: $prices$”)
// result: name: chicken and Prices: 200$
Your code doesn’t compile for multiple reasons. I suggest you work through the Kotlin Koans to learn the basics: Kotlin Playground: Edit, Run, Share Kotlin Code Online
fun main(args: Array<String>) {
//sampleStart
data class Container(val food: String, val prices: List<Int>)
var (food , prices) = Container("chicken", listOf(100,200,300,400))
println( "Food: $food and Prices: $prices")
//sampleEnd
}
Be sure to read the compiler errors. All of the changes I made were from following the process: Read the first error, fix it, repeat.
Basicaly programming
Reading and understanding compiler errors is one of the most important skills a programmer can have. And kotlin in general has good and easier to understand error messages, which should make it easier.