Skip to content

Instantly share code, notes, and snippets.

@felipebelluco
Created November 20, 2018 13:29
Show Gist options
  • Save felipebelluco/616342f4f067d878d2b5ad0ac84c8076 to your computer and use it in GitHub Desktop.
Save felipebelluco/616342f4f067d878d2b5ad0ac84c8076 to your computer and use it in GitHub Desktop.
// source: https://pt.slideshare.net/haimyadid/building-microservices-with-kotlin
interface DBEnum {
val id: Int
val dbName: String
companion object {
inline fun <reified T> fromId(id: Int): T where T : Enum<T>, T : DBEnum =
enumValues<T>().first { it.id == id }
inline fun <reified T> fromName(name: String): T where T : Enum<T>, T : DBEnum =
enumValues<T>().first { it.dbName == name }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment