dimanche 7 octobre 2018

How to check the type of Kotlin variable

I'm writing a Kotlin program where type of variable is inferred but later on I wish to know the what type of value this variable stores. I tried following but it shows following error.

Incompatible types: Float and Double


val b = 4.33 // inferred type of what
if (b is Float) {
    println("Inferred type is Float")
} else if (b is Double){
    println("Inferred type is Double")        
}

Aucun commentaire:

Enregistrer un commentaire