Examveda

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)
}

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


This Question Belongs to Computer Science >> Kotlin Program

Join The Discussion

Related Questions on Kotlin Program

What is Kotlin?

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.