Delegated properties in Kotlin allow you to delegate the responsibility of getting and setting a property to another object. This feature can help you manage property behavior more cleanly and concisely, especially when dealing with common patterns like lazy initialization, observable properties, or storing properties in a map. By using delegated properties, you can reduce boilerplate code and improve readability.
class User { var name: String by lazy { "Default Name" } var age: Int by Delegates.observable(0) { _, old, new -> println("Age changed from $old to $new") } } fun main() { val user = User() println(user.name) // Output: Default Name user.age = 25 // Output: Age changed from 0 to 25 }