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.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.