You pass an integer to a function expecting type Any. It works without issue. Why is a primitive integer able to work with a function that expects an object?
fun showHashCode(obj: Any){
println("${obj.hasCode()}")
}
fun main() {
showHashCode(1)
}
fun showHashCode(obj: Any){
println("${obj.hasCode()}")
}
fun main() {
showHashCode(1)
}A. While the code runs, it does not produce correct results
B. The integer is always a class
C. The compiler runs an implicit .toClass() method on the integer
D. The integer is autoboxed to a Kotlin Int class
Answer: Option D
Related Questions on Kotlin Program
A. A new version of Java.
B. A JavaScript framework.
C. A statically-typed programming language for the JVM, Android, and browser.
D. A database management system.
Which platform does Kotlin primarily target?
A. Python Bytecode
B. JavaScript
C. JVM (Java Virtual Machine) Bytecode
D. PHP

Join The Discussion