Destructuring cho phép bạn tách một object thành các biến riêng lẻ trong một câu lệnh duy nhất.
Ví dụ val (name, age) = person trích xuất thuộc tính từ data class.
Destructuring allows you to break down an object into individual variables in a single statement.
- For example,
val (name, age) = personextracts properties from a data class. - You can also destructure in loops:
for ((key, value) in map). - This works with data classes, pairs, lists, and makes code more readable when working with multiple values.