I am new to Kotlin and I have an enum containing many values, those values refer to different states my application has.
Now I need to log something whenever the app enters a state but some state in the enum can log more than one thing (based on other parameters coming from outside the app) and some state does not need to log something.
Here is my enum:
enum class StateName(vararg log: String) {
FIRST_CONNECTION(), // no parameter here
AUTHORIZATION_CHECK("message 1", "message 2"),
HANDSHAKE_SUCCESS("message")
//...
}
If had declared the enum with a single obligatory parameter StateName(var log: String)
I could have used HANDSHAKE_SUCCESS.log
to retrieve its value but with vararg
the IDE (android studio) does not find log
at all.
So how can I retrieve my string with something like log[0]
?
Note:
You need to change it to:
enum class StateName(vararg val log: String)
This way you can access the log
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With