什么是"::"?在科特林意味着什么? [英] what does "::" mean in kotlin?

查看:76
本文介绍了什么是"::"?在科特林意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Kotlin的新手
我使用以下代码打开了另一个活动:

I'm new to Kotlin
I used this code for opening another activity:

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

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

current activity and target activity are written in Kotlin

我不明白为什么在IntroAndLang::class.java上没有单个:而不是::

I cant understand why there is not single : instead of :: at IntroAndLang::class.java

推荐答案

类参考: 最基本的反映功能是将运行时参考引入Kotlin类.要获取对静态已知的Kotlin类的引用,可以使用类文字语法:

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.

请注意,Kotlin类引用与Java类引用不同. 要获取Java类引用,请在KClass实例上使用.java属性.

也是方法引用的语法,如以下简单示例所示:

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

list.forEach(::println)

它是指Kotlin标准库中定义的println.

It refers to println defined in Kotlin Standard library.

这篇关于什么是"::"?在科特林意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆