I have a simple Kotlin class, that does not declare a companion object.
class Foo
I would love to create an extension for companion object, even if one is not specified. I do not want to create an empty companion object.
fun Foo.Companion.bar()
How?
What is the difference between:
Foo
Foo
?
I would love to create an extension for companion object, even if one is not specified.
Why?
How?
You can't. An extension, by definition, is something that extends ... something. You can't extend a non-existent entity. Remember that extension functions are basically static functions that take an instance of the extending object as the first parameter. So your example:
fun Foo.Companion.bar()
Would translate to:
public static void bar(Foo.Companion objectBeingExtended) { }
How is that supposed to work if Foo.Companion
doesn't exist?