fun main(arg: Array<String>) { val map = mapOf("name" to "tom", "age" to 20 ) val user = user(map) println(user.name) println(user.age) } class user(var map:Map<String,Any>){ val name:String by map val age:Int by map }
使用场景:将map中key-value映射到对象的属性中,这通常在解析json 数据时用到