I still not understand with it ? help me!


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: https://try.kotlinlang.org/#/Kotlin%20Koans/Introduction/Hello,%20world!/Task.kt

fun main(args: Array<String>) {
    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")

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 :wink:
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.