Mikhail
05/11/2022, 4:05 PMval (first, second!!) = Pair<String, String?>("not null", "same")
// so I dont have to:
val (first, second) = Pair<String, String?>("not null", "same")
// and then
val secondNotNull = second!!Fleshgrinder
05/11/2022, 4:27 PMKlitos Kyriacou
05/11/2022, 4:31 PMval secondNotNull = second!!, all you have to do is second!! by itself on the next line, and then just use second (smart cast).
Alternatively, val (first, second) = foo() as Pair<String, String> but you'll get a warning.Mikhail
05/11/2022, 4:32 PMMikhail
05/11/2022, 4:34 PM!! each time I access the variable. It's not a big problem to consume a nullable value and use !! once.Klitos Kyriacou
05/11/2022, 4:34 PMsecond!! once. Not every time you access it.Mikhail
05/11/2022, 4:35 PMMikhail
05/11/2022, 4:35 PMFleshgrinder
05/11/2022, 4:37 PMrequireNotNull and checkNotNull and any other function that defines an appropriate contract:
val (first, second) = f() // Pair<String, String?>
second!!
requireNotNull(second) { "imposibru!" }
checkNotNull(second) { "impsibru!" }
second // definitely not null here 8)Mikhail
05/11/2022, 4:40 PMFudge
05/12/2022, 10:31 PM