Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

Create a function in Kotlin that takes an enum parameter

$
0
0

I'm creating a function that takes an enum value as a parameter, but I am very new to Kotlin and I can't find any material that covers this specifically.

Example:

enum class Color(val rgb: Int) {        RED(0xFF0000),        ORANGE(0xffa500),        YELLOW(0xffff00),        GREEN(0x00FF00),        BLUE(0x0000FF),        INDIGO(0x4b0082),        VIOLET(0x8F5E99)}fun getHexColor (Color: Enum){    when(x){        Color.BLUE -> println("Battle")        else -> print("otherwise")    }}

I get an error that says:

One type argument expected for class Enum<E: Enum<E>>

I've looked through Kotlin documentation for over an hour and I've got nothing to show for it... do any of you have an idea of how to use this class as a parameter?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>