Home > Enterprise >  Is it possible to nest an enum contains class's properties within an open class?
Is it possible to nest an enum contains class's properties within an open class?

Time:03-16

I've read enter image description here

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

  • Related