Incomplete code with Elvis operator and addition in Kotlin
I am learning Kotlin and I happened to write this:
var nullTest: Int? = null
println(nullTest?++ ?:0)
Trying to compile and run, I get the "incomplete code" error. Same with:
var nullTest: Int? = null
println(nullTest?+1 ?:0)
While if I use:
var nullTest: Int? = null
println(nullTest?.inc() ?:0)
It compiles and runs correctly. Why is that so? Why do I have to use .inc() and can't I just use the + operator?
Thank you