Steve
12/02/2019, 5:02 PMRuckus
12/02/2019, 5:03 PMStrings.kt
, Collections.kt
, etc.)serebit
12/02/2019, 5:04 PMadimit
12/02/2019, 5:04 PMSteve
12/02/2019, 5:07 PMHullaballoonatic
12/02/2019, 6:35 PMclass Sum(initial: Double = 0.0) {
private var sum = initial
operator fun plusAssign(num: Double) {
sum += num
}
}
// boilerplate stuff.
// unneccessary to understand how the class works.
// if declared in the class, only muddies up readability
operator fun Sum.plusAssign(num: Int) = plusAssign(num.toDouble())
Hullaballoonatic
12/02/2019, 6:39 PMObject
, which is analogous to a singleton class in Java:
object Util {
fun parse(inputString: String) = ...
}
Often however there's no reason to do this over just declaring them top-level.
note that top level functions can have visibility set like any internal functions or values