What kind of inheritance is this? I see it in Comp...
# announcements
m
What kind of inheritance is this? I see it in Compose docs, but can't find its usage on Kotlin docs. Can a subclass (object) be defined inside the parent class?
👌 1
Copy code
sealed class Screen(val route: String, @StringRes val resourceId: Int) {
    object Profile : Screen("profile", R.string.profile)
    object FriendsList : Screen("friendslist", R.string.friends_list)
}
m
It’s normal inheritance. The only difference is that you can be sure that
Profile
and
FriendsList
are the only subclasses of
Screen
and there are no others. That’s because it’s
sealed
. https://kotlinlang.org/docs/sealed-classes.html
âž• 1
m
I don't know why the linked doc does not have an example like the given snippet.