tpgillam
12/18/2020, 1:48 PMval x = foo() ?: return moo, where foo(): T? is a method returning a nullable generic T?. Now previously, x was of type T, however now the IDE is telling me that it is of type T!!. I can seemingly force it to be of type T, however can somebody explain what is going on here? I also can't find the relevant part of documentation that explains what !! means when postfixing a (possibly only generic?) type. Thanks!Marc Knaup
12/18/2020, 1:55 PMSomething!!. That’s probably either an IDE bug or a compiler bug.tpgillam
12/18/2020, 2:03 PMtpgillam
12/18/2020, 2:03 PMtpgillam
12/18/2020, 2:04 PMtpgillam
12/18/2020, 2:04 PMtpgillam
12/18/2020, 2:04 PMMarc Knaup
12/18/2020, 2:04 PMtpgillam
12/18/2020, 2:05 PMdata class Wrapper<T>(val value: T)
class Moo<T> {
fun moo(): T? {
return null
}
fun foo(): List<Wrapper<T>> {
val x = moo() ?: return listOf()
val list = mutableListOf<Wrapper<T>>()
list.add(Wrapper(x))
return list
}
}Marc Knaup
12/18/2020, 2:07 PMMarc Knaup
12/18/2020, 2:07 PMtpgillam
12/18/2020, 2:07 PMtpgillam
12/18/2020, 2:07 PMMarc Knaup
12/18/2020, 2:08 PMMarc Knaup
12/18/2020, 2:08 PMMarc Knaup
12/18/2020, 2:08 PMMarc Knaup
12/18/2020, 2:08 PMT is nullable. So T!! literally means a non-null T.tpgillam
12/18/2020, 2:09 PMtpgillam
12/18/2020, 2:13 PMT actually means a type that isn't null: class Moo<T: Any> . Then the compiler is happy that Wrapped<T!!> is the same as Wrapped<T>, I think.tpgillam
12/18/2020, 2:13 PMMarc Knaup
12/18/2020, 2:22 PM