In kotlin, it's possible to check via reflection i...
# reflect
v
In kotlin, it's possible to check via reflection if property was declared as nullable. For example, the following code
Copy code
public class Magic {
  private val foo: String? = null
  private val bar: String = "not"
}

public fun main(args: Array<String>) {
  Magic::class.members.forEach {
    println("${it.name}, nullable = ${it.returnType.isMarkedNullable}")
  }
}
prints:
Copy code
bar, nullable = false
foo, nullable = true
equals, nullable = false
hashCode, nullable = false
toString, nullable = false
The question is, how is
KType.isMarkedNullable
implemented? I don't see any nullability information in generated bytecode. Public properties are annotated with
NotNull
and
Nullable
annotations, but private ones don't have such annotations. (I'm doing some bytecode instrumentation and want to know if field is nullable or not)