class MyClass {
fun myFun() = runBlocking {
val wrongClass = this.javaClass // ❌
val myClass = this@MyClass.javaClass // ✅
}
}
p
Pihentagy
06/23/2023, 8:30 AM
Thanks.
Huh, logical, but huh. So excatly what will it be? How is that possible then that I see all instance fields?
s
Sam
06/23/2023, 8:33 AM
When I said the receiver is “replaced”, that’s actually a bit of a simplification. Actually the original receiver is still there. When you bring a new receiver into scope, its members will shadow the members of the existing receivers. So you can see all the original instance fields, as long as they don’t share the same name as a property belonging to the new receiver.
p
Pihentagy
06/23/2023, 8:34 AM
And can I achieve that without mentioning the actual classname? (so without MyClass)
s
Sam
06/23/2023, 8:38 AM
Not really, but you could work around it by just extracting another function:
Copy code
@GetMapping("/health-check")
fun healthCheck() = runBlocking {
mapOf(
"version" to getImplementationVersion(),
)
}
fun getImplementationVersion() = javaClass.`package`.implementationVersion