Skip to content

Instantly share code, notes, and snippets.

@CheolhoJeon
Created June 17, 2021 03:09
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/50a46e98cf8cdbbd690b2e6fb7e869e5 to your computer and use it in GitHub Desktop.
Save CheolhoJeon/50a46e98cf8cdbbd690b2e6fb7e869e5 to your computer and use it in GitHub Desktop.
package chap5.CompanionObjects
import atomictest.eq
class WithNamed {
companion object Named {
fun s() = "from Named"
}
}
class WithDefault {
companion object {
fun s() = "from Default"
}
}
fun main() {
WithNamed.s() eq "from Named"
WithNamed.Named.s() eq "from Named"
WithDefault.s() eq "from Default"
// The default name is "Companion":
WithDefault.Companion.s() eq "from Default"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment