Skip to content

Instantly share code, notes, and snippets.

@bekwam
Created August 16, 2018 11:16
Show Gist options
  • Save bekwam/64a796fec2c598c0555b89e57bc11d8b to your computer and use it in GitHub Desktop.
Save bekwam/64a796fec2c598c0555b89e57bc11d8b to your computer and use it in GitHub Desktop.
Kotlin Class With Surrogate Key Field
data class ClassWithSurrogateKey(val field1 : String, val field2 : Int) {
val id = nextId() // always increasing
companion object {
private var idgen = 1 // faux static class member
fun nextId() = idgen++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment