What is the difference between sealed class vs sealed interface in kotlin

A major reason to choose to use a sealed class instead of interface would be if there is common property/function that you don’t want to be public. All members of an interface are always public.

The restriction that members must be public can be worked around on an interface using extension functions/properties, but only if it doesn’t involve storing state non-publicly.

Otherwise, sealed interfaces are more flexible because they allow a subtype to be a subclass of something else, an enum class, or a subtype of multiple sealed interface/class hierarchies.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)