Allow a property of a data class to only accept certain values

Some context first. In Android using Kotlin, changing the visibility is done like in the following.

myView.visibility = View.VISIBLE

Setting any other Int value other than View.VISIBLE, View.INVISIBLE or View.GONE returns an error.

Now I have a Kotlin data class that accepts a constructor parameter flag of type Int.

How do I implement this the same way in my Kotlin code such that myClass.flag = Flag.A and no other value?



Read more here: https://stackoverflow.com/questions/64945249/allow-a-property-of-a-data-class-to-only-accept-certain-values

Content Attribution

This content was originally published by Praanto Samadder at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: