The Companions to Come
Kotlin 2.5.0 introduces experimental companion blocks and extensions, allowing static‑like members on any class and enabling cross‑platform compilation changes. The feature requires compiler flags –Xcompanion-blocks and –Xcompanion-blocks-and-extensions, and impacts Kotlin Multiplatform static member handling.

JetBrains announced experimental companion blocks and extensions in Kotlin 2.5.0 to replace traditional companion objects for static-like members. These features allow developers to define type-level functionality directly on any class or interface, regardless of origin. The syntax closely mirrors previous companion object patterns but triggers distinct compilation behaviors. Users must enable specific compiler flags to access these capabilities. One flag permits only the new block syntax, while a second flag unlocks extensions for external types. These mechanisms address limitations inherent in the existing companion object system. This update improves interoperability by compiling companion blocks as static members on the Java Virtual Machine. Such alignment simplifies work for Kotlin Multiplatform projects that require Java static members. Developers can now define expected members and provide actual implementations using standard Java classes. The changes also allow adding new members to types without controlling the original source code. This capability extends to interfaces and Java-originated classes. JetBrains suggests that new code should prefer this block syntax over the older object approach for constants and factory methods. The features remain experimental and generate pre-release binaries when extensions are used. Libraries utilizing these extensions may face consumption restrictions until the status stabilizes. While the design aims for broader compatibility, existing companion objects remain fully supported and guaranteed. Migration requires recompiling affected projects and dependencies. Some ecosystem tooling might not yet support the new syntax. The team advises caution as they work with major players to ensure readiness.