huehnerlady
05/18/2021, 10:26 AMudalov
isMarkedNullable
returns false correctly, in the sense that it is not true that the type has been explicitly marked as nullable, as is the case with Kotlin nullable types, but of course that’s not very useful.
Kotlin-reflect doesn’t have an API to detect flexible types, but it should. There’s an open issue about it: https://youtrack.jetbrains.com/issue/KT-15987
You can use a workaround like this to detect Java nullability-flexible types:
fun KType.isNullabilityFlexible(): Boolean =
!isMarkedNullable && this != withNullability(false) && this != withNullability(true)