Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. class UserResponse(val map: Map<String, Any?>) {
  2. val user: User by map
  3. }
  4.  
  5. class User(val map: Map<String, Any?>) {
  6. val name: String by map
  7. val age: Int by map
  8. }
  9.  
  10. fun main(args: Array<String>) {
  11. val user = mapOf(
  12. "name" to "Jack",
  13. "age" to 40
  14. )
  15. val response = mapOf(
  16. "user" to User(user)
  17. )
  18.  
  19. val userResponse = UserResponse(response)
  20. println(userResponse.user.name) // Prints "Jack"
  21. println(userResponse.user.age) // Prints 40
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement