what does “::” mean in kotlin?

前端 未结 4 1560
灰色年华
灰色年华 2020-12-04 18:13

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

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

current activity

4条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-04 18:39

    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.

提交回复
热议问题