https://kotlinlang.org logo
#language-proposals
Title
# language-proposals
b

benleggiero

02/26/2017, 9:24 PM
when
should know when it's been exhaustive if it's evaluating a `sealed class`'s
KClass
. For instance:
Copy code
sealed class MySealedClass {
    class SubclassA: MySealedClass()
    class SubclassB(val date: Date): MySealedClass()
}

fun makeInstance(sealedClass: KClass<MySealedClass>): MySealedClass
    = when (sealedClass) {
        SubclassA::class -> SubclassA()
        SubclassB::class -> SubclassB(Date())
    }
Error:
Kotlin: 'when' expression must be exhaustive, add necessary 'else' branch
o

orangy

02/27/2017, 5:14 PM
Thanks!
5 Views