Suppose I have the following code :
fun main() {
val userName: String? = "Dmitry" // line 1
userName?.takeLast(2)?.reversed() // line 2
userName?.plus("kotlin").plus("lang") // line 3
}
I can’t get the reason for the usage of Elvis operator before reversed()
– why it is not possible to use just .
? As I can see in doc takeLast()
always provides String
, not String?
. The same scenario works for Line 3 in my example -> plus()
always returns String so there is no need of Elvis before the Second plus()
?