mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
Effectively, the following when structure:
when (s) {
s1, s2 -> e1,
s3 -> e2,
s4 -> e3,
...
else -> e
}
is implemented as:
when (s.hashCode()) {
h1 -> {
if (s == s1)
e1
else if (s == s2)
e1
else if (s == s3)
e2
else
e
}
h2 -> if (s == s3) e2 else e,
...
else -> e
}
where s1.hashCode() == s2.hashCode() == s3.hashCode() == h1,
s4.hashCode() == h2.
A tableswitch or lookupswitch is used for the hash code lookup.
Change-Id: I087bf623dbb4a41d3cc64399a1b42342a50757a6
15 lines
256 B
Kotlin
Vendored
15 lines
256 B
Kotlin
Vendored
fun foo() : Int {
|
|
val x : String = "dsa"
|
|
when (x) {
|
|
"a" -> return 1
|
|
"b" -> return 1
|
|
"c" -> return 1
|
|
"d" -> return 1
|
|
"e" -> return 1
|
|
"f" -> return 1
|
|
else -> return -1
|
|
}
|
|
}
|
|
|
|
// 1 TABLESWITCH
|