For_class_not_object
Use companion object, add empty companion object if you don't have one in your class.
Follow the code example:
interface OutFactory {
/**
* Empty companion object is added to provide a hook-up for writing extension
* methods on the OutFactory 'class'.
*
* Typical extension methods will work on instance, of a class/interface
* This will allow creation of extension methods for a class. */
companion object
fun OutFactory.Companion.consoleFactory(): OutFactory {
return object : OutFactory {
override fun getOutForClass(classHoldingOut: KClass<*>): Out {
// Return a console-specific Out implementation
return SimpleConsoleOut(
classHoldingOut,
shouldIncludeElapsedTime = true,
logLevelProvider = LogLevelProvider.LOG_ALWAYS
)
}
}
}
Backlinks