Checking data type with when() example
Checking data type with when() example
In this short note, you can see an example of when() usage with data type. The type of data will determine the code to run.
val x : Any = 12.75
when(x){
is Int -> println("$x is an Integer")
is Double -> println("$x is a Double")
is String -> println("$x is a String")
else -> println("$x is not Int,Double or String")
}
You can see the output below.
Last updated on