Slackbot
11/03/2026, 8:25 AMCLOVIS
11/03/2026, 8:26 AMCLOVIS
11/03/2026, 8:27 AMCLOVIS
11/03/2026, 8:34 AMCLOVIS
11/03/2026, 8:35 AMCLOVIS
11/03/2026, 8:35 AMApi private?CLOVIS
11/03/2026, 8:37 AMApi?CLOVIS
11/03/2026, 8:38 AMcompanion object , just put stuff in the companion object , no need for three added layersCLOVIS
11/03/2026, 8:39 AMCLOVIS
11/03/2026, 8:40 AMclass MyType {
companion object {
fun f() {}
}
}CLOVIS
11/03/2026, 9:16 AMsealed interface MyInt {
val int: Int
sealed interface Even : MyInt
sealed interface Odd : MyInt
private data class EvenImpl(
override val int: Int,
) : Even
private data class OddImpl(
override val int: Int,
): Odd
companion object {
fun of(int: Int): MyInt =
if (int % 2 == 0) EvenImpl(int) else OddImpl(int)
}
}Marat Akhin
11/03/2026, 9:18 AMCLOVIS
11/03/2026, 9:18 AMCLOVIS
11/03/2026, 9:21 AMCLOVIS
11/03/2026, 9:36 AMonce a module with a sealed interface is compiled, no new implementations can be created.This is a stronger guarantee than what Java's package-private gives you, but it's not relevant to your example. Sealed class implementations must be in the same package as the sealed class itself, no need to create new modules.
CLOVIS
11/03/2026, 9:39 AMYour approach doesn't scale because each new declaration (one change) in eitherThat's not "one" change. That's a change to the public API and a change to the implementation. It's the same in your example, you have to change bothorEventakes making changes in two places.Odd
Api and Impl.Companion .
From the point of view of the user, my version exposes 1 sealed interface, its 2 implementations and one constructor, which is the minimal API surface required by your use-case. I would argue exposing so many additional symbols is much worse for maintainability than editing a function and its implementation (both in the same file)