enumValueOf
Returns the enum entry of type T with the specified name.
The name must exactly match an existing enum constant of type T (case-sensitive).
Since Kotlin
1.1Throws
Samples
import kotlin.enums.enumEntries
import kotlin.test.*
fun main() {
//sampleStart
// enum class Direction { NORTH, SOUTH, EAST, WEST }
val east = enumValueOf<Direction>("EAST")
println(east) // EAST
// The lookup fails if a string does not correspond to any of the enum entries
// enumValueOf<Direction>("UP") // will fail with IllegalArgumentException
// enumValueOf<Direction>("") // will fail with IllegalArgumentException
// The lookup is case-sensitive and fails if the name doesn't match any constant
// enumValueOf<Direction>("east") // will fail with IllegalArgumentException
//sampleEnd
}Returns the enum entry of type T with the specified name.
The name must exactly match an existing enum constant of type T (case-sensitive).
Since Kotlin
1.1Throws
Samples
import kotlin.enums.enumEntries
import kotlin.test.*
fun main() {
//sampleStart
// enum class Direction { NORTH, SOUTH, EAST, WEST }
val east = enumValueOf<Direction>("EAST")
println(east) // EAST
// The lookup fails if a string does not correspond to any of the enum entries
// enumValueOf<Direction>("UP") // will fail with IllegalArgumentException
// enumValueOf<Direction>("") // will fail with IllegalArgumentException
// The lookup is case-sensitive and fails if the name doesn't match any constant
// enumValueOf<Direction>("east") // will fail with IllegalArgumentException
//sampleEnd
}Returns the enum entry of type T with the specified name.
The name must exactly match an existing enum constant of type T (case-sensitive).
Since Kotlin
1.1Throws
Samples
import kotlin.enums.enumEntries
import kotlin.test.*
fun main() {
//sampleStart
// enum class Direction { NORTH, SOUTH, EAST, WEST }
val east = enumValueOf<Direction>("EAST")
println(east) // EAST
// The lookup fails if a string does not correspond to any of the enum entries
// enumValueOf<Direction>("UP") // will fail with IllegalArgumentException
// enumValueOf<Direction>("") // will fail with IllegalArgumentException
// The lookup is case-sensitive and fails if the name doesn't match any constant
// enumValueOf<Direction>("east") // will fail with IllegalArgumentException
//sampleEnd
}Returns the enum entry of type T with the specified name.
The name must exactly match an existing enum constant of type T (case-sensitive).
Since Kotlin
1.3Throws
Samples
import kotlin.enums.enumEntries
import kotlin.test.*
fun main() {
//sampleStart
// enum class Direction { NORTH, SOUTH, EAST, WEST }
val east = enumValueOf<Direction>("EAST")
println(east) // EAST
// The lookup fails if a string does not correspond to any of the enum entries
// enumValueOf<Direction>("UP") // will fail with IllegalArgumentException
// enumValueOf<Direction>("") // will fail with IllegalArgumentException
// The lookup is case-sensitive and fails if the name doesn't match any constant
// enumValueOf<Direction>("east") // will fail with IllegalArgumentException
//sampleEnd
}Returns the enum entry of type T with the specified name.
The name must exactly match an existing enum constant of type T (case-sensitive).
Since Kotlin
1.8Throws
Samples
import kotlin.enums.enumEntries
import kotlin.test.*
fun main() {
//sampleStart
// enum class Direction { NORTH, SOUTH, EAST, WEST }
val east = enumValueOf<Direction>("EAST")
println(east) // EAST
// The lookup fails if a string does not correspond to any of the enum entries
// enumValueOf<Direction>("UP") // will fail with IllegalArgumentException
// enumValueOf<Direction>("") // will fail with IllegalArgumentException
// The lookup is case-sensitive and fails if the name doesn't match any constant
// enumValueOf<Direction>("east") // will fail with IllegalArgumentException
//sampleEnd
}Returns the enum entry of type T with the specified name.
The name must exactly match an existing enum constant of type T (case-sensitive).
Since Kotlin
1.8Throws
Samples
import kotlin.enums.enumEntries
import kotlin.test.*
fun main() {
//sampleStart
// enum class Direction { NORTH, SOUTH, EAST, WEST }
val east = enumValueOf<Direction>("EAST")
println(east) // EAST
// The lookup fails if a string does not correspond to any of the enum entries
// enumValueOf<Direction>("UP") // will fail with IllegalArgumentException
// enumValueOf<Direction>("") // will fail with IllegalArgumentException
// The lookup is case-sensitive and fails if the name doesn't match any constant
// enumValueOf<Direction>("east") // will fail with IllegalArgumentException
//sampleEnd
}