Completed Coursera: Kotlin for developers course
This commit is contained in:
30
src/Conditionals.kt
Normal file
30
src/Conditionals.kt
Normal file
@ -0,0 +1,30 @@
|
||||
import Color.*;
|
||||
|
||||
fun main() {
|
||||
when (RED) {
|
||||
RED -> println("red")
|
||||
BLUE -> println("blue")
|
||||
GREEN -> println("green")
|
||||
}
|
||||
|
||||
when ("y") {
|
||||
"yes", "y" -> println("Yes")
|
||||
else -> println("No")
|
||||
}
|
||||
|
||||
val b: A = B()
|
||||
|
||||
when (b) {
|
||||
// Smart cast b to the type B
|
||||
is B -> println("B")
|
||||
else -> println("Unknown")
|
||||
}
|
||||
}
|
||||
|
||||
enum class Color {
|
||||
BLUE, GREEN, RED
|
||||
}
|
||||
|
||||
open class A
|
||||
|
||||
class B : A()
|
Reference in New Issue
Block a user