pablisco
02/02/2019, 4:01 PMStefan Beyer
02/02/2019, 5:28 PMStefan Beyer
02/02/2019, 5:31 PMStefan Beyer
02/02/2019, 5:41 PM&&
and ||
it is irrelevant, but look at this:
fun main() {
val x = 5
+ 4
- 5
println("x is $x")
val y = 5 +
4 -
5
println("y is $y")
}
it will print out
x is 5
y is 4
pablisco
02/02/2019, 5:52 PM+
and -
is that these are actually "sugarized" functions in Kotlin where as &&
are actually operators.
That example is interesting, why does it do that? 🤔 (To the ide...)Stefan Beyer
02/02/2019, 6:02 PMval x = 5
4.unaryPlus()
5.unaryMinus()
Marc Knaup
02/02/2019, 6:10 PM&&
and ||
at the beginning of each line because that way you see that logic faster and the operators are always at the same horizontal position rather than jumping a lot depending on the length of each line.
I'm used to do the same with all operators but it took me days to notice that it led to wrong computations because Kotlin treated +
and -
as unary operators in the continuation lines without warning, which for me was quite unexpected.
So in that case I either have to put them at the end or wrap everything into braces.