-1

I am trying to send a simple explicit intent to start a new activity , I previously used to code in Java & the syntax was pretty simple , I switched to kotlin recently & I have no idea what the :: or the .java extension at the end is doing ?

fun Run(view: View) {
    
    // what the heck is :: ? why do i have a .java at the end ?
    val intent:Intent= Intent(this, MainActivity2::class.java)
    startActivity(intent)
}
deepeshdm
  • 43
  • 4

1 Answers1

2

:: creates a member reference or a class reference

Here what it does is getting the reference to MainActivity2. In Java you'd do this with MainActivity2.class.

In Kotlin, MainActivity::class returns a value of type KClass, which is different from Java class reference. But the Intent function expects a Java class reference, so you use the .java property on the reference to get the Java class reference