David Kubecka
01/31/2023, 7:17 PMval newStage = when {
expiresInDays >= 2 -> 0
expiresInDays in 0..1 -> 1
expiresInDays < 0 -> 2
else -> 3
}
generates a warning Condition 'expiresInDays < 0' is always true
in IDEA? (expiresInDays
is of type Long.)ephemient
01/31/2023, 7:20 PMexpiresInDays
is a val
, the IDE inspection knows that the first 3 cases cover everything. Kotlin doesn't, though: https://youtrack.jetbrains.com/issue/KT-34548David Kubecka
01/31/2023, 7:24 PMexpiresInDays < 0
David Kubecka
01/31/2023, 7:24 PMexpiresInDays
is valDavid Kubecka
01/31/2023, 7:25 PMephemient
01/31/2023, 7:26 PMval newStage = when {
expiresInDays >= 2 -> 0
expiresInDays in 0..1 -> 1
true -> 2
else -> 3
}
David Kubecka
01/31/2023, 7:26 PMephemient
01/31/2023, 7:28 PMexpiresInDays >= 2 ->
, expiresInDays in 0..1 ->
, and else ->
as the three cases, the compiler will know it's exhaustive and you also don't have IDE warningsKlitos Kyriacou
02/01/2023, 10:28 AMwhen
statements/expressions, making "else" redundant (except after "if"). But "else" sounds more sensible anyway.ephemient
02/01/2023, 2:54 PM| otherwise ->
. that isn't a language keyword, it's just defined as otherwise = True
.