Reputation: 10723
When creating a private companion object
in Kotlin, why is the Companion
static variable marked as @Deprecated public
in the bytecode? Is that just a workaround to "simulate" a private
behaviour discouraging developers from using that field (since a public companion object doesn't get marked as deprecated)?
Example:
class MyClassWithCompanion {
private companion object {
private val FOO = "FOO"
}
}
// DEPRECATED
// access flags 0x20019
public final static LMyClassWithCompanion$Companion; Companion
@Ljava/lang/Deprecated;()
Upvotes: 2
Views: 375
Reputation: 97268
The @Deprecated
annotation is placed as an intermediate solution to avoid breaking binary compatibility when a compiler bug was fixed. The field wasn't supposed to be generated as public when the companion object is private, but due to an oversight it was. In Kotlin 1.4, it will be marked as private.
See this issue for more information.
Upvotes: 3