Jonathan Lennox
10/03/2023, 3:34 PMclass Person(val firstName: String, val lastName: String, val age: Int) {
override fun toString(): String {
return "$firstName $lastName is $age years old"
}
}
would be preferred over
class Person(val firstName: String, val lastName: String, val age: Int) {
override fun toString(): String {
return firstname + " " + lastName + " is " + age + " years old"
}
}
Should it?Paul Dingemans
10/03/2023, 7:40 PMfun foo() =
fooBar
.filter { it.bar() }
.map { it.text }
+ " some other text"
This is also a string concatenation. Inlining the expression inside the string would result is less readable code:
fun foo() =
"${fooBar
.filter { it.bar() }
.map { it.text }} some other text"
It will be hard to decide in which case if would be beneficial to use string template and when not.Jonathan Lennox
10/03/2023, 7:44 PM