3

Kotlin has this noarg plugin to generate a synthetic noarg constructor for classes without one to help JPA (and frameworks like mybatis, hibernate) to instantiate a new object. Ex:

data class User(val id: Int, val name: String)

Given these properties are declared as val, i.e. immutable, how do these frameworks go about creating a fully baked object with all the values set. The kotlin-noarg plugin is just helping in instantiating a new instance, but the properties (id and name) are still immutable and hence shouldn't be allowed to change once the object is created.

To be clear, things work perfectly fine after adding the noarg plugin. The question is how, given that the properties are immutable.

This SO question too talks about this solution, but not the how part.

Sourabh
  • 429
  • 1
  • 4
  • 11

0 Answers0