Reputation: 1338
When I define an enum class in Kotlin
enum class Answer {
YES,
NO
}
It has a valueOf(value: String)
attached to it.
val doYouWantBeerOrCoffee = Answer.valueOf("YES") // Answer.YES
But where is this function actually defined? It is definitely not in the Enum.Kt and using Idea's Go to Implementation
tool only takes me back to my Answer
enum definition.
Upvotes: 2
Views: 302
Reputation: 170745
It's generated by the compiler. That's what "synthetic" means in
If you decompile Answer.class
you'll see it, but it isn't written as Kotlin (or Java) source code anywhere.
Upvotes: 1
Reputation: 171
This method is a part of JDK, and defined in Enum.java
class.
Which is the common base class of all Java language enumeration types.
Kotlin uses the same class for enums
Upvotes: 0