如何在 Kotlin 中获取数据类型

msm*_*919 2 android kotlin

在 JavaScript 中:

var a = 10;
console.log(typeof a); // It's return data type 'Number'
Run Code Online (Sandbox Code Playgroud)

如何在 Kotlin 中获取数据类型?

var a:Int = 10
println(/* What is the code? */)
Run Code Online (Sandbox Code Playgroud)

我刚开始学习 Kotlin。我搜索了文档,但找不到。

huy*_*ytc 6

您可以像这样获取变量的类

var a : Int = 10
println(a::class.simpleName) // Int
// or
println(a::class.qualifiedName) // kotlin.Int
Run Code Online (Sandbox Code Playgroud)