• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

apply 표준함수 체이닝

21.05.11 15:25 작성 조회수 83

0

apply를 여러번 하지않고 this.result 구성할 때 description과 userRequest에 대해서 구성하면 안되나요?

답변 1

답변을 작성해보세요.

0

Hoon님의 프로필

Hoon

2021.05.15

return UserResponse().apply {
this.result = Result().apply {
this.resultCode = "OK"
this.resultMessage = "성공"
}
//--
this.description = "!!!"

val users = mutableListOf<UserRequest>()

users.add(userRequest)

users.add(UserRequest().apply {
this.name = "a"
this.age = 10
this.email = "a@a.com"
this.address = "a address"
this.phoneNumber = "01012341234"
})

users.add(UserRequest().apply {
this.name = "b"
this.age = 10
this.email = "b@b.com"
this.address = "b address"
this.phoneNumber = "01012341234"
})

this.userRequest = users
}

이렇게 해도 되지 않느냐는 말씀이신가요? 테스트 해봤는데 정상 작동하네요. 이해를 돕기 위해 JSON계층과 똑같은 계층으로 메세지를 채워나간 것 아닌가 추측해봅니다.