Want to get type of a variable in Kotlin? You can use the is operator to check whether an object is of a specific type:
1 2 3 4 | val number = 5 if(number is Int) { println("number is of type Int") } |
You can also get the type as String using reflection:
1 2 3 4 5 | // "Int" println("${number::class.simpleName}") // "kotlin.Int" println("${number::class.qualifiedName}") |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.