274
CHAPTER 10: Development
Table 10-2. Kotlin Operators
Symbol
Translates to
Infix
Default Function
+a
a.unaryPlus()
Usually does nothing.
-a
a.unaryMinus()
Negates a number.
!a
a.not()
Negates a Boolean expression.
a++
a.inc()
Increments a number.
a- -
a.dec()
Decrements a number.
a + b
a.plus(b)
x
Addition.
a - b
a.minus(b)
x
Subtraction
a * b
a.times(b)
x
Multiplication.
a / b
a.div(b)
x
Division.
a % b
a.rem(b)
x
Remainder after division.
a . . b
a.rangeTo(b)
x
Defines a range.
a in b
b.contains(a)
x
Containment check.
a !in b
!b.contains(a)
x
Not-containment check.
a[i]
a.get(i)
Indexed access.
a[i,j,...]
a.get(i,j,...)
Indexed access, normally not used.
a[i] = b
a.set(i,b)
Indexed setting access.
a[i,j,...] = b
a.set(i,j,...,b)
Indexed
setting access, normally not
used.
a()
a.invoke()
Invocation.
a(b)
a.invoke(b)
Invocation.
a(b,c,...)
a.invoke(b,c,...)
Invocation.
a += b
a.plusAssign(b)
x
Adds to a. Must not return a value;
instead, you must modify this.
a -= b
a.minusAssign(b)
x
Subtracts from a.
Must not return a
value; instead, you must modify this.
a *= b
a.timesAssign()
x
Multiplies to a. Must not return a value;
instead, you must modify this.
a /= b
a.divAssign(b)
x
Divides a by b and then assigns. Must
not return a value; instead, you must
modify this.
a %= b
a.remAssign(b)
x
Takes the remainder
of the division by
b and then assigns. Must not return a
value; instead, you must modify this.
a == b
a?.equals(b) ?: (b
=== null)
x
Checks equality.
(
continued)