Basic for Enum [Java/Kotlin]


This article describes useful Enum value for Java and Kotlin.

🎳 Useful Enum class

enum class RecyclerType constructor(val int: Int) {
BODY(1),
HEADER(2)
FOOTER(3);

companion object {
// Convert to enum
fun fromInt(index: Int): RecyclerType {
return values().firstOrNull { it.int == index } ?: BODY
}
}

val isBody: Boolean
get() = this == BODY

val isFooter: Boolean
get() = this == FOOTER
}

🐝 References

🖥 Recommended VPS Service

VULTR provides high performance cloud compute environment for you. Vultr has 15 data-centers strategically placed around the globe, you can use a VPS with 512 MB memory for just $ 2.5 / month ($ 0.004 / hour). In addition, Vultr is up to 4 times faster than the competition, so please check it => Check Benchmark Results!!