Working with enum constants

EnumClass.valueOf(value: String): EnumClass
EnumClass.values(): Array<EnumClass>
enum class Track { 
ID,
ARTIST,
ALBUM,
TITLE,
GENRE
}
inline fun <reified T : Enum<T>> getTrackInfo() {
// print out all the items
print(enumValues<T>().joinToString { it.name })
}
inline fun <reified T : Enum<T>> getTrackInfo() = enumValues<T>().map { it }fun example(): List <Track> {
// return a list of all the items
getTrackInfo<Track>()
}
val name: String
val ordinal: Int

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

{UPDATE} spot forskellen billedet jagt puslespil-sølv udgave Hack Free Resources Generator

Managing Group Projects

Gutenberg: from the drama to the real life

The 2021 US Championship: PRA Case Study

Custom Keyboard in SwiftUI

Microapps — the good, the bad and the ugly

geometric shapes with light

Tips for neater Android development — Part 1

Working with container register + Azure functions + Docker + Node js.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Bunni

Bunni

More from Medium

How and When to convert a Utility function in Kotlin to an Extension Function

Android View Binding Without Boilerplate  —  Part 1

Kotlin When Expression

Room Migrations — “Testing”