class Product {
var id = 0
companion object {
var nextId: Int
init {
nextId = getLastDbId()
}
private fun getLastDbId(): Int {
//some implementation
return 0
}
}
init {
nextId++
id = nextId
}
}
val man1 = Product()
//man1.id is 1
val man2 = Product()
//man2.id is 2
println("man1.id is ${man1.id}")
println("man2.id is ${man2.id}")