Login
Remember
Register
Ask a Question
How would you refactor this code using apply?
0
votes
asked
Oct 6, 2021
in
Kotlin
by
Robin
How would you refactor this code using apply?
Problem
Consider:
class Message(message: String, signature: String) {
val body = MessageBody()
init {
body.text = message + "\n" + signature
}
}
Do you see any refactoring that could be done?
kotlin-code
Please
log in
or
register
to answer this question.
1
Answer
0
votes
answered
Oct 6, 2021
by
Robin
You can write:
class Message(message: String, signature: String) {
val body = MessageBody().apply {
text = message + "\n" + signature
}
}
...