Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When we start new activity into kotlin why we put .java in intent instead of .kt

Tags:

android

kotlin

As per kotlin doc we start new activity with following syntax

startActivity(Intent(this@MainActivity, NextActivity::class.java))

its kotlin so why we add .java after the the class ? why not kt?

like image 231
Dayanand Waghmare Avatar asked Oct 24 '25 16:10

Dayanand Waghmare


1 Answers

Because NextActivity::class gives you KClass<NextActivity>, and KClass has a method/extension property called java which gives you the java.lang.Class<NextActivity> for the given class.

You can even check out the source-code for that java property.

like image 186
EpicPandaForce Avatar answered Oct 26 '25 05:10

EpicPandaForce



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!