How can I create static method for enum in Kotiln?

Technology CommunityCategory: KotlinHow can I create static method for enum in Kotiln?
VietMX Staff asked 3 years ago

Just like with any other class, you can define a class object in an enum class:

enum class CircleType {
  FIRST,
  SECOND,
  THIRD;
  companion object {
     fun random(): CircleType = FIRST
  }
}

Then you’ll be able to call this function asĀ CircleType.random().