Created
November 20, 2018 13:29
-
-
Save felipebelluco/616342f4f067d878d2b5ad0ac84c8076 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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