does Any == Object

前端 未结 4 1413
花落未央
花落未央 2021-01-07 16:25

The following code in kotlin:

Any().javaClass

Has value of java.lang.Object. Does that mean Any and Object<

4条回答
  •  -上瘾入骨i
    2021-01-07 16:50

    Kotlin compiler treats kotlin.Any and java.lang.Object as two different types, but at runtime they are represented with the same java.lang.Object class.

    javaClass property returns the runtime class of an instance, so that's why you get the same java.lang.Object class in both cases.

    There are also other types which are different at compile time, but the same at runtime; they are listed in the Mapped types section of the documentation.

提交回复
热议问题