what does “::” mean in kotlin?

前端 未结 4 1559
灰色年华
灰色年华 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:22

    Since kotlin 1.1, in addition to class, function, property and constructor references as stated above, '::' can also be used to obtain the bound references to all of the above.

    For instance, using '::class' could be used to get the exact class of a particular object despite the type of the receiver as below...

    val widget: Widget = ...
    assert(widget is GoodWidget) { "Bad widget: ${widget::class.qualifiedName}" }
    

    widget::class returns the exact class of the object 'widget' as either 'GoodWidget' or 'BadWidget' despite the type of the receiver expression (i.e 'Widget' as declared initially)

    More info at https://kotlinlang.org/docs/reference/reflection.html

提交回复
热议问题