Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class UserResponse(val map: Map<String, Any?>) {
- val user: User by map
- }
- class User(val map: Map<String, Any?>) {
- val name: String by map
- val age: Int by map
- }
- fun main(args: Array<String>) {
- val user = mapOf(
- "name" to "Jack",
- "age" to 40
- )
- val response = mapOf(
- "user" to User(user)
- )
- val userResponse = UserResponse(response)
- println(userResponse.user.name) // Prints "Jack"
- println(userResponse.user.age) // Prints 40
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement