Kotlin data class optional variable

You can set default values in your primary constructor as shown below.

data class Student(val id: Int = Int.MIN_VALUE,
               val firstName: String,
               val lastName: String,
               val hobbyId: Int = Int.MIN_VALUE,
               val address1: String = "",
               val address2: String = "",
               val created: String = "",
               val updated: String = "")

Then you can use named arguments when creating a new student instance as shown below.

Student(firstName = "Mark", lastName = "S")

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)