Hello, Can you tell me difference between interfac...
# getting-started
ö
Hello, Can you tell me difference between interface and sealed interface, I checked the Kotlin docs but I didn't find a detailed explanation. When we should sealed interface instead normal interface? What featutes does sealed interface have?
e
same as the difference between
open class
and
sealed class
(
interface
defaults to
open
instead of
final
like
class
does because that wouldn't make sense)
the docs cover both
sealed class
and
sealed interface
https://kotlinlang.org/docs/sealed-classes.html
ö
Okey thank you for replying :)
h
A sealed interface is a special type of interface that can have a limited set of implementations, and all of these implementations must be defined within the same file or a set of related files (known as a compilation unit)
👍 1
think enum but for inheritance
Copy code
sealed interface Result

class Success : Result
class Failure : Result
e
Use sealed interface, when you hit any “restrictions”, consider if changing to an interface is what you want
👍 1