androidkotlin

How to get data type in Kotlin


In javascript:

var a = 10;
console.log(typeof a); // It's return data type 'Number'

How to get data type in Kotlin?

var a:Int = 10
println(/* What is the code? */)

I just started learning Kotlin. I searched the document but could not find it.


Solution

  • You can get the class of a variable like this

    var a : Int = 10
    println(a::class.simpleName) // Int
    // or
    println(a::class.qualifiedName) // kotlin.Int