Hey guys I was curious is there was a super class that all classes that have a companion object inherit, and thusly can be extended?
To enable the use of extension methods such as:
Copy code
inline fun <reified T : Any> T.Companion.extensionMethod = ...
z
Zach Klippenstein (he/him) [MOD]
01/15/2021, 12:44 AM
There is not.
Zach Klippenstein (he/him) [MOD]
01/15/2021, 12:44 AM
You could request it in #C0B9K7EP2
a
Andrew Adams
01/15/2021, 12:45 AM
Ok, thanks!
t
Tobias Berger
01/15/2021, 3:08 PM
but what's the point? Methods in companion objects are basically what would be
static
in Java. If you have a static method/companion object function that exists in every class, why not just leave out the class and make it a global function? If you need the reified type, you can just provide it in the call like this
Copy code
inline fun <reified T : Any> logger() = LoggerFactory.getLogger(T::class.java)