Android – When we start new activities to kotlin why we put .java in intent instead of .kt

According to kotlin doc, we use the following syntax to start a new activity

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

It’s kotlin, why do we add .java after class? Why not kt?

Because NextActivity :: class provides you with KClass< NextActivity>, and KClass has a name java methods/extended attributes, it provides you java.lang.Classfor a given class.

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

According to the kotlin doc, we use the following syntax to start a new activity

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

It’s kotlin, why do we add .java after class? Why not kt?

Because NextActivity::class provides you with KClass, and KClass has a method/extension called java Attribute, it provides you java.lang.Classfor a given class.

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

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3559 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.