dave08
10/07/2021, 3:52 PMinterface Foo {
fun printlog(msg: String) = "... - $msg"
}
class Bar : Foo
How can I get the printlog in the interface to print out Bar - some message
? If I use ${this::class.simpleName}
it just gives me the interface's name...Joffrey
10/07/2021, 3:55 PM${this::class.simpleName}
does work: https://pl.kotl.in/3LrWAHRvp
interface Foo {
fun printlog(msg: String) = "${this::class.simpleName} - $msg"
}
class Bar : Foo
fun main() {
val log = Bar().printlog("hello")
println(log)
}
This correctly prints Bar - hello
printlog
on something that's not an instance of Bar
maybe?dave08
10/07/2021, 3:57 PMinterface BaseResult {
fun toLogFmt(): String =
"type=${this::class.simpleName} literal=${toString()}"
}
fun interface ResultUseCase2<in Request : Any, out Result : BaseResult> : UseCase<Request, Result> {
suspend fun doAction(request: Request): Result
override suspend fun invoke(request: Request): Result =
doAction(request).also { <http://logger.info|logger.info> { it.toLogFmt() } }
}
UseCase
instead of the type of result... my results are a sealed interface inherited from BaseResult and data classes inhereted from the sealed interface... I guess my example out there was oversimplified...Joffrey
10/07/2021, 4:05 PMdave08
10/07/2021, 4:07 PMJoffrey
10/07/2021, 4:09 PMdave08
10/07/2021, 5:33 PMJoffrey
10/07/2021, 6:33 PMkotlin-reflect
for simpleName
.