Sargun Vohra
10/05/2026, 3:13 AMenum class and sealed aren't called out as compatibility hazards; why not?
As long as I have such things in my public api, unless I use the @Deprecated NonExhaustive = 0 trick, every additional value is a source and runtime breaking change, correct?
Is there a common way to deal with such things? For now I'm converting enum class to value classCLOVIS
10/05/2026, 7:10 AMCLOVIS
10/05/2026, 7:10 AMmbonnin
10/05/2026, 8:14 AMevery additional value is a sourceyes
and runtime breaking change, correct?Every bugfix is a runtime breaking change. As long as the new enum is behind a flag, it could be OK for your consumers
mbonnin
10/05/2026, 8:18 AMmbonnin
10/05/2026, 12:07 PMCLOVIS
10/05/2026, 12:20 PMSargun Vohra
10/05/2026, 4:44 PMAdding a new enum value is binary compatible though
What do exhaustive when expressions do with that new value? I'd expect an exception of some kind, practically not so different from a method call whose signature changed
Behind a flag
How do I put an enum behind a flag? Oh, if I understand you right, you mean as long as the library doesn't return the new value without some caller-side change?
mbonnin
10/05/2026, 4:57 PMWhat do exhaustive when expressions do with that new value?Yep, you'll get a
NoWhenBranchMatchedException
if I understand you right, you mean as long as the library doesn't return the new value without some caller-side changeYes. Just like you have a function that returns
Int between 0 and 10 and starts returning 50. If the caller code doesn't expect the new value, it crashesmbonnin
10/05/2026, 4:57 PMSargun Vohra
10/05/2026, 5:07 PMSargun Vohra
10/05/2026, 5:08 PMAdam S
10/05/2026, 5:26 PMI noticed however thatThey probably should be, please make a YT issueandenum classaren't called out as compatibility hazards; why not?sealed
Adam S
10/05/2026, 5:29 PMval.
Con: it's verbose and you have to remember to keep everything in sync.
Pro: internally you can use an exhaustive-when
sealed class FooMode {
companion object {
@JvmStatic // in case you have non-Kotlin users
val Alpha: FooMode = AlphaInternal
@JvmStatic
val beta: FooMode = BetaInternal
}
internal data object AlphaInternal : FooMode()
internal data object BetaInternal : FooMode()
}