Is there a way to list all properties of an object that are allowed to return nulls?
val cls = javaClass<T>().kotlin
for(property in cls.properties) {
if(property.accessible) {
//Is it nullable?
}
}
The API you're looking for was introduced in latest Kotlin builds (0.13.213+). You can now take the type of a property and find out if it was marked as nullable in the source code:
val property = ...
if (property.returnType.isMarkedNullable) {
...
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With