Last active
February 22, 2019 14:38
-
-
Save renaudcerrato/803b5fbb3899f321175cf80f3e0cd395 to your computer and use it in GitHub Desktop.
Kotlin Object Singleton
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
// 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