<@U0BDMQTHS> describes in his (fantastic) presenta...
# language-proposals
v
@mikehearn describes in his (fantastic) presentation how much pain companion objects cause when creating idiomatic Java API. Main points: - functions and properties require a ton of
@JvmStatic
and
@JvmField
- references to companion objects pollute Java API and IDE code completion I propose reinterpreting currently useless
private companion object {...}
in a way that from Kotlin the companion object cannot be used and companion members can only be called on the class itself, and from Java all companion members are static methods and fields. An example:
Copy code
class A {
    private companion object {
        val bar = 239
        fun foo() = "hello"
    }
}
, Kotlin:
Copy code
A.foo()  // ok
A.bar    // ok
A.Companion.foo()  // Error
A.Companion.bar     // Error
, Java:
Copy code
A.foo();  // ok
A.bar;    // ok
A.Companion // Error
What do you think? Has it been discussed before ?