The way creating no-arg constructor in kotlin

Initialize default value for all of parameters.

1
2
3
4
5
6
7
8
9
class Sheet(
@Id
val id: Long = 1,

val name: String = "",

val author: String = "",
) {
}

Create secondary constructor that initialize each fields.

1
2
3
4
5
6
7
8
9
10
class Sheet(
@Id
val id: Long,

val name: String,

val author: String,
) {
constructor(): this(1, "", "")
}

Use no-arg plugin

1
2
3
4
5
6
7

// build.gradle.kts

plugins {
// ...
kotlin("plugin.jpa") version "1.6.10"
}
Share