Skip to content

Instantly share code, notes, and snippets.

@renaudcerrato
Last active February 22, 2019 14:38
Show Gist options
  • Save renaudcerrato/803b5fbb3899f321175cf80f3e0cd395 to your computer and use it in GitHub Desktop.
Save renaudcerrato/803b5fbb3899f321175cf80f3e0cd395 to your computer and use it in GitHub Desktop.
Kotlin Object Singleton
// object class as a singleton
object Log {
val prop = 42
fun debug(msg: String) { ... }
fun info(msg: String) { ... }
fun warn(msg: String) { ... }
fun error(msg: String) { ... }
}
// object classes can inherit from classes and interfaces
object DirectExecutor: Executor {
override fun execute(r: Runnable) = r.run()
}
DirectExecutor.execute( runnable {
Log.debug("executing...")
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment