How to create an empty constructor for data class in Kotlin Android?
Hello everyone! I'm new to Kotlin and Android development. I have a problem with data class. \n\nIn Java, I'm used to writing POJO classes with empty constructors, so that I can later fill fields through setters or use libraries like Gson for serialization/deserialization. But in Kotlin, data class requires all fields to be declared in the primary constructor. For example, like this:\n\n```kotlin\ndata class User(val name: String, val age: Int)\n```\n\nBut what if I need to create a User object without initial values and then fill them? For example, when working with Firebase or Retrofit, when data arrives in parts. I tried to write:\n\n```kotlin\ndata class User(val name: String = "", val age: Int = 0)\n```\n\nBut this is not exactly an empty constructor, but a constructor with default values. Moreover
No answers yet.
Log in to leave an answer
Blogs