https://kotlinlang.org logo
#getting-started
Title
# getting-started
m

miha-x64

01/12/2017, 9:48 AM
Finally, I got this:
Copy code
private val nameToEnum = hashMapOf<String, Event>()
enum class Event(val myName: String) {
    IMPRESSION("impression"),
    CLICK_THROUGH("clickThrough");

    companion object {
        fun fromName(name: String): Event {
            return nameToEnum[name]!!
        }
    }

    init {
        nameToEnum.put(name, this)
    }
}