Reputation: 2887
So in Swift you can do something like:
public enum OuterEnum {
public enum InnerEnum {
...
}
}
What would the equivalent be in Kotlin to contain an enum inside an enum?
Upvotes: 5
Views: 8134
Reputation: 30645
You can create an inner enum as follows:
enum class OuterEnum {
OUTER_ITEM1;
enum class InnerEnum {
INNER_ITEM1, INNER_ITEM2
}
}
Or if you don't have items in the OuterEnum
:
enum class OuterEnum {
;
enum class InnerEnum {
INNER_ITEM1, INNER_ITEM2
}
}
Note that there is a semicolon before declaration of the InnerEnum
.
To use it just call:
val item = OuterEnum.InnerEnum.INNER_ITEM1
Upvotes: 20