apatrida
12/26/2015, 4:13 PMLazy
to act as a delegate for a logger for the enclosing class:
public fun <R : Any> R.logger(): Lazy<Logger> {
return lazy { Logger.getLogger(unwrapCompanionClass(this.javaClass).name) }
}
Then use this function as a delegate:
class Something {
val LOG by logger() // really calling extension seen as Something.logger()
fun foo() {
<http://LOG.info|LOG.info>("Hello from Something")
}
}
more in the SO link above. Add a comment if you think differently about what is more common or not, and if there are variations missing that are useful.