我是新来Kotlin 的
我使用此代码打开另一个活动:

startActivity(Intent(this,IntroAndLang::class.java))

当前活动和目标活动用Kotlin编写

我不明白为什么IntroAndLang::class.java号楼没有:号房而是::号房?

推荐答案

As stated in the docs this is a class reference:

Class References: The most basic reflection feature is getting the runtime reference to a Kotlin class. To obtain the reference to a statically known Kotlin class, you can use the class literal syntax:

val c = MyClass::class
//The reference is a value of type KClass.

Note that a Kotlin class reference is not the same as a Java class reference. To obtain a Java class reference, use the .java property on a KClass instance.

It’s also the syntax for method references as in this simple example:

list.forEach(::println)

It refers to println defined in Kotlin Standard library.

Kotlin相关问答推荐

在Kotlin 有更好的结合方式?

编译后的JavaFX应用程序立即以静默方式崩溃

我需要后台工作才能使用卡夫卡的消息吗?

如何使用函数类型或 lambdas 作为 Kotlin 上下文接收器的类型?

为什么在 Kotlin 中调用私有构造函数会导致错误为无法访问 是什么?

Kotlin - mutableMapOf() 会保留我输入的顺序

变量后的Android问号

如何解决此错误请Kotlin:[Internal Error] java.lang.ExceptionInInitializerError

ActivityOptions.makeSceneTransitionAnimation 在具有多个视图的 kotlin 中不起作用

如何在 Spring WebFlux 的响应正文中流式传输二进制数据

Jacoco在Gradle 7.0.2和Kotlin 1.5.10上失败

main函数和常规函数有什么区别?

RecyclerView SnapHelper无法显示第一个/最后一个元素

Kotlin 的 Double.toInt() 中使用了哪种方法,舍入还是截断?

用Gradle Kotlin DSL构建源jar?

Kotlin 警告:Conditional branch result of type ... is implicity cast of Any?

如果kotlin已经有了getter和setter,为什么在数据类中有componentN函数?

如何在 IntelliJ IDEA 中禁用粘贴时将 Java 转换为 Kotlin?

Kotlin中默认导入哪些包/函数?

使用 Kotlin 按字母对数组进行排序