How to customize toString() method for enum in Kotlin?
enum class GuideType(type: String) {
DEF_TYPE("default"),
override fun toString(): String {
return type // not working!
}
}
Default constructor params need to be either var
or val
to be accessible outside the init
block. Also you need to add semicolor after last enum item to add any new functions or overrides.
enum class GuideType(var type: String) {
DEF_TYPE("default");
override fun toString(): String {
return type // working!
}
}
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