如何在现有的Android应用程序中使用Kotlin? [英] How to Use Kotlin in an Existing Android App?

查看:80
本文介绍了如何在现有的Android应用程序中使用Kotlin?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用Java开发的Android应用.我现在想开始将Kotlin用于同一应用程序.可以在现有应用中同时使用Kotlin和Java吗?

I have an Android App developed using Java. I now want to start using Kotlin for the same app. Is it possible to use Kotlin and Java side-by-side in an existing app?

推荐答案

是的,您可以在一个项目中混合使用Java和Kotlin.

Yes you can mix Java and Kotlin in one project.

从Android 文档:

如果您对使用Kotlin感兴趣,那么就很容易上手,因为 它与Java和Android上的C ++并存.这样你就可以保持 您现有的代码,继续使用各种Android库,以及 将Kotlin代码逐步添加到您的项目中.与几乎其他任何东西都不一样 语言,Kotlin是您可以使用的替代产品 双向-您可以从Kotlin调用Java语言,并且 您可以使用Java语言调用Kotlin.

If you're interested in using Kotlin, it's easy to get started because it works side by side with Java and C++ on Android. So you can keep your existing code, continue to use the various Android libraries, and incrementally add Kotlin code to your project. Unlike almost any other language, Kotlin is a drop-in replacement you can use bi-directionally—you can call into the Java language from Kotlin, and you can call into Kotlin from the Java language.

此外,您还应该查看kotlin官方 doc

Also you should take a view of kotlin official doc

您还可以使用IntelliJIDEA将Java代码转换为Kotlin.

You can also convert Java code to Kotlin with IntelliJIDEA.

这篇关于如何在现有的Android应用程序中使用Kotlin?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆