Find properties with a null value through reflection

Is there a way to list all the properties of an object that are allowed to return zeros?

val cls = javaClass<T>().kotlin for(property in cls.properties) { if(property.accessible) { //Is it nullable? } } 
+5
source share
1 answer

The API you are looking for has been introduced in recent Kotlin builds (0.13.213+). Now you can take the type of the property and find out if it was marked as zero in the source code:

 val property = ... if (property.returnType.isMarkedNullable) { ... } 
+9
source

All Articles