How to create empty constructor for data class in Kotlin?
If you give default values to all the primary constructor values, you shall automatically create an empty constructor for data class.
For example, if you have a data class like this:
data class Activity(
var updated_on: String,
var tags: List
var description: String,
var user_id: List
)
And you want to initialize the data class with an empty constructor, all you have to do is assign the default values to all the primary constructors, like this:
data class Activity(
var updated_on: String = "",
var tags: List
var description: String = "",
var user_id: List
)
BY Best Interview Question ON 17 Aug 2020