Skip to content

Instantly share code, notes, and snippets.

@CheolhoJeon
Created June 17, 2021 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CheolhoJeon/02b1ad5de46e47483fa782e6ab8ca098 to your computer and use it in GitHub Desktop.
Save CheolhoJeon/02b1ad5de46e47483fa782e6ab8ca098 to your computer and use it in GitHub Desktop.
package chap5.CompanionObjects
import atomictest.eq
class WithObjectProperty {
companion object {
private var n: Int = 0 // Only one
}
fun increment() = ++n
}
fun main() {
val a = WithObjectProperty()
val b = WithObjectProperty()
a.increment() eq 1
b.increment() eq 2
a.increment() eq 3
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment