https://kotlinlang.org logo
#announcements
Title
# announcements
d

Dennis Schröder

08/24/2019, 10:41 AM
Anybody also wondering about this topic? When does a when expression in kotlin need to be exhaustive and when does it not? https://github.com/Dobiasd/articles/blob/master/when_does_a_when_expression_in_kotlin_need_to_be_exhaustive_and_when_does_it_not.md
k

karelpeeters

08/24/2019, 2:20 PM
I think there are two separate things here: • there is a warning for enums and not for sealed classes • whether or not a when is a lambda is considered an expression depends on the possible (?) return type. I'm curious as to how the exact decision making for this process goes, this is a minimal example:
Copy code
run {
	when(Foo.A) {
		Foo.A -> Unit
	}
}
run {
	when(Foo.A) {
		Foo.A -> 5
	}
}
2 Views