sealed class Gender{

data class Male(...)

data class Female(...)


val g:Gender = Gender.Female(...)


is Gender.Male -> {/*do something*/}

is Gender.Female ->{/*do something*/}

else -> {/*do something*/}



as you can see Sealed classes provide a enum like syntax for doing stuff... we are actually comparing the instance type of our object, which could be of one of the children of sealed class, but never the sealed class itself.

g could never be defined as :

val g = Gender()


curiously fiddling around with tech | also @anshsachdevaprofessional

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store