Saiedmomen
06/10/2021, 11:41 AMrequireNotNull
does not provide smart cast null safety. Is there another way to concisely mark null as Illegal state and have smart cast?
private var id: Long? = null
override fun delete() = runBlocking {
requireNotNull(id)
notesRepository.deleteNote(id!!) // id is not smart cast to not null
}
Hasan Hosgel (alosdev)
06/10/2021, 11:45 AMPetter Måhlén
06/10/2021, 11:46 AMnotesRepository.deleteNote(requireNotNull(id))
?Nikky
06/10/2021, 11:49 AMNikky
06/10/2021, 11:50 AMvar
that could change between the check and the usageSaiedmomen
06/10/2021, 11:51 AMNikky
06/10/2021, 11:52 AMif(id != null) {
notesRepository.deleteNote(id)
}
it should warn you that it cannto smartcast id
Nikky
06/10/2021, 11:55 AMlet
or similar scope functions
but best would be if you can get rid of the var
.. or change it into a parameter.. which also makes it immutable in the scope of the functionSaiedmomen
06/10/2021, 11:56 AM