This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.CompanionObjects | |
import atomictest.eq | |
class WithObjectProperty { | |
companion object { | |
private var n: Int = 0 // Only one | |
} | |
fun increment() = ++n | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.CompanionObjects | |
import atomictest.eq | |
class WithNamed { | |
companion object Named { | |
fun s() = "from Named" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.CompanionObjects | |
import atomictest.eq | |
class WithCompanion { | |
companion object { | |
val i = 3 | |
fun f() = i * 3 | |
} | |
fun g() = i + f() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.Object | |
import atomictest.eq | |
object Outer { | |
object Nested { | |
val a = "Outer.Nested.a" | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.Object.objectsharing | |
object Shared { | |
var i: Int = 0 | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.Object.objectsharing | |
object Shared { | |
var i: Int = 0 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.Object | |
import atomictest.eq | |
open class Paint(val color: String) { | |
open fun apply() = "Applying $color" | |
} | |
object Acrylic: Paint("Blue") { | |
override fun apply() = "Acrylic, ${super.apply()}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package chap5.Object | |
import atomictest.eq | |
object JustOne { | |
val n = 2 | |
fun f() = n * 10 | |
fun g() = this.n * 20 // [1] | |
} |