To alter Enum properties by extracting data class, you can follow these steps:
data class MyDataClass(val value1: String, val value2: Int)
enum class MyEnum {
VALUE1 {
override fun getDataClass(): MyDataClass {
return MyDataClass("value1", 1)
}
},
VALUE2 {
override fun getDataClass(): MyDataClass {
return MyDataClass("value2", 2)
}
};
abstract fun getDataClass(): MyDataClass
}
val data1 = MyEnum.VALUE1.getDataClass()
val value1 = data1.value1 // "value1"
val value2 = data1.value2 // 1
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2023-05-25 16:13:52 +0000
Seen: 19 times
Last updated: May 25 '23
What is the method to alter the background image in HTML?
Is it not possible to alter the value of MutableState in an if statement?
What is the process for altering the value of a variable in pyqt6?
Is it possible to alter the request headers of outgoing requests using a Chrome Extension?
How can one obtain live data from interactive broker through API?
What is the method to implement pagination for Firestore data in Flutter using ListView?
What is the reason for the submitted Django form's value being null in the database?
How can we create summary tables by using nested tibbles?
What is the process of moving information from one tab to another in Excel by transposing it?