Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
471 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...