Rob Elliot
06/04/2023, 1:50 PMis
check and smart cast in a when
statement? Problem in thread...Rob Elliot
06/04/2023, 1:51 PMAdam S
06/04/2023, 1:57 PMT
.
inline fun <reified T> fetch(key: String): Outcome<FailedLookupResult, T> =
ifContains(key) {
when (val candidate = get(key)) {
is T -> candidate.success()
null -> NullValue(key).failure()
else -> UnexpectedType(key, candidate).failure()
}
}
(Using reified
might not be necessary - I can’t remember off the top of my head)Rob Elliot
06/04/2023, 1:58 PMAdam S
06/04/2023, 1:59 PMMatteo Mirk
06/13/2023, 3:10 PMT:JsonNode
@Adam S reified is needed only if you need to access T
inside the function, so I'd say yes in this case it's mandatory