I have data class with default values.
data class Project(
val code: String,
val name: String,
val categories: List<String> = emptyList())
Java reflection fails to instantiate the class when some values are null. I'm getting exception
java.lang.IllegalArgumentException: Parameter specified as non-null is null: method Project.<init>, parameter categories
This is because java.lang.reflect.Constructor<T>.instantiateClass
method expects arguments that are not null.
I have the type information, I have the constructor definition but I'm not sure how to call the constructor so that it uses the default values (The values are coming from the database and categories
can be null
). Is there any way to achieve this in Kotlin?
Aucun commentaire:
Enregistrer un commentaire