当我们在 kotlin 中开始新活动时,为什么我们将 .java 放入 Intent 而不是 .kt

问题描述:

根据 kotlin 文档,我们使用以下语法开始新活动

As per kotlin doc we start new activity with following syntax

startActivity(Intent(this@MainActivity, NextActivity::class.java))

它的 kotlin 那么为什么我们在类之后添加 .java 呢?为什么不是kt?

its kotlin so why we add .java after the the class ? why not kt?

因为 NextActivity::class 给你 KClassKClass 有一个名为 java 为您提供给定类的 java.lang.Class.

Because NextActivity::class gives you KClass<NextActivity>, and KClass has a method/extension property called java which gives you the java.lang.Class<NextActivity> for the given class.

你甚至可以查看该java 属性的源代码.

You can even check out the source-code for that java property.