I was wondering if it is possible in Kotlin?
CodePudding user response:
The problem is that txtNode
is an instance variable. Different BaseCase
instances could have different values. So the enum cannot know which one of them to take.
Let's for simplicity say txtNode
is a String
instead of an UiObject
Then how would the following code work?
val a = BaseCase()
a.txtNode = "test"
val b = BaseCase()
b.txtNode = "test2"
val c = BaseCase.TextType.PlainText
would c
have "test" or "test2" as field? It simply isn't possible.
CodePudding user response:
that's because enum class are final static classes ---> you cannot access non static variables. for testing -> if you move your variable to companion object the code will work