We have to write this line with the extension .java although its extension is .kt I think Kotlin file converts into the java file but the java also converts in byte code so we can also use .class file If the Kotlin code converts into the java code.
NextActivity::class.java
to NextActivity::class.kt //not worked
btn?.setOnClickListener {
startActivity(Intent(this, NextActivity::class.java))
}
So the question is why we write the .java in NextActivity::class.java
Question arises from here.
Because you want to access the methods of the Java Class.
I think they are not reimplemented from scratch in Kotlin so, in order to access them, you have to "reflect" your kotlin class to a Java one.
NextActivity::class
returns the KClass
reference and the KClass
has the property java
and the Intent
contructor signature is Intent(Context packageContext, Class cls)
so the second parameter is Class
type So the final answer would be this is not the extension this is just property.