[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2023-09-19。"],[],[],null,["# Kotlin on Android FAQ\n\n#### Why did Android make Kotlin a first-class supported language?\n\nKotlin is an Android-compatible language that is concise, expressive, and\ndesigned to be type- and null-safe. It works with the Java programming language\nseamlessly,\nso it makes it easy for developers who love Java to keep using it while\nincrementally adding Kotlin code and leveraging Kotlin libraries. Meanwhile,\nmany Android developers have found that Kotlin makes development faster\nand more fun, so Google wants to better support these Kotlin users. Read\nmore about [Android's Kotlin-first approach](/kotlin/first).\n\n#### How do I use Kotlin with Android Studio?\n\nKotlin is fully supported in [Android Studio](/studio). All new releases of\nAndroid Studio ship with support for creating new projects with Kotlin files,\nconverting Java language code to Kotlin, debugging Kotlin code, and\nmore.\n\n#### How do I debug Kotlin in Android Studio?\n\nDebugging Kotlin works just like debugging Java code. You don't need to do\nanything differently.\n\n#### What kind of other IDE support is provided for Kotlin (like lint,\n\nautocomplete, and refactoring)?\n\n[Android Studio](/studio) has full tooling support for Kotlin.\n\n#### What's the future of Kotlin?\n\nJetBrains' thoughtful work on Kotlin's design is one of the reasons to\nembrace the language. Google is partnering with JetBrains to ensure a\nwonderful overall developer story---from language to framework to tools.\nWe're excited to be working together to move the Kotlin language into a\nnot-for-profit foundation.\n\n#### Is Kotlin open source?\n\nThe preferred license for Kotlin is the\n[Apache Software License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)\n(\"Apache 2.0\"), and the majority of the Kotlin software is licensed under\nit. While the project strives to adhere to the preferred license,\nthere can be exceptions, which are handled on a case-by-case basis. For\nexample, certain third-party dependencies used by Kotlin are licensed under\ndifferent open-source licenses that are still compatible with the Apache 2.0\nlicense.\n\n#### How do I choose between the Java and Kotlin languages?\n\nYou don't have to pick! You can use both. If you need\nhelp discovering whether Kotlin is a good fit for you, you can\n[try it on Android](/kotlin) or learn more about the language\nwith [these Kotlin resources](/kotlin/getting-started-resources).\n\n#### Can I call Android or other Java language library APIs from Kotlin?\n\nYes. Kotlin provides Java language interoperability. This design lets\nKotlin code transparently call Java language methods, coupled with\nannotations that make it easy to expose Kotlin-only functionality to Java code.\nKotlin files that don't use any Kotlin-specific semantics can be directly\nreferenced from Java code without any annotations at all. Combined, this lets\nyou granularly mix Java code with Kotlin code. To learn more, see\n[Kotlin's interop documentation](https://kotlinlang.org/docs/reference/java-interop.html).\n\n#### Do you have Kotlin reference docs for Android APIs?\n\nYep! Google is working to make all Android API documentation available with\nidiomatic Kotlin references. You can\nfind links to the available Kotlin reference docs on the\n[Android reference overview page](/reference/kotlin). If you're looking for a\ncore Kotlin language reference, see the\n[Kotlin standard library reference](https://kotlinlang.org/api/latest/jvm/stdlib/index.html).\n\n#### Can I use both Java files and Kotlin files in the same project?\n\nYes. You can adopt as much or as little Kotlin as you like and mix it with Java\ncode using [Kotlin's interoperability with Java](https://kotlinlang.org/docs/reference/java-interop.html).\n\n#### Can I use Kotlin with C++?\n\nYes, JNI is fully supported with Kotlin. Mark JNI methods with\n[the external modifier](https://kotlinlang.org/docs/reference/java-interop.html#using-jni-with-kotlin).\n\n#### How do I add Kotlin to my new projects?\n\nWhen creating new projects, Kotlin is now the default language choice in Android Studio. For more information, see [Create a project](/studio/projects/create-project).\n\n#### How do I add Kotlin to my existing projects?\n\nSelect your module in the **Project** window, and then select **File \\\u003e New** .\nSelect any Android template, and then choose **Kotlin** as the\n**Source language** . For more information, see\n[Add Kotlin to an existing app](/kotlin/add-kotlin).\n\n#### How do I convert Java language code to Kotlin?\n\nOpen a Java file and select **Code \\\u003e Convert Java File to Kotlin File** . Or,\ncreate a new Kotlin file (**File \\\u003e New \\\u003e Kotlin File/Class** ), and then paste\nyour Java code into that file. When prompted, click **Yes** to convert the code\nto Kotlin.\n| **Note:** Be sure to review any converted code and ensure that your tests continue to pass.\n\n#### Will there be parallel docs, samples, codelabs, and templates in Kotlin?\n\nWe're working to make our documentation and educational materials as useful as\npossible to both Java and Kotlin language users. In the meantime, developers\ncan rely on Kotlin's excellent interoperability with the Java language and the\nability to automatically translate Java language code to Kotlin in Android\nStudio.\n\n#### Do Kotlin coroutines work on Android? How about async/await?\n\nKotlin coroutines are stable as of Kotlin version 1.3 and work as intended on\nAndroid. For more information on using coroutines with Android, see\n[Improve app performance with Kotlin coroutines](/kotlin/coroutines).\n\n#### Does using Kotlin have any performance impact?\n\nKotlin doesn't have a direct performance impact, but just as with the Java\nlanguage, you should be thoughtful about how you use it. For example, repeated\ncopying between new collection instances can impact GC performance, and calling\na method that accepts non-null types adds a method call for the null check\n(though you can disable runtime null checks in the compiler with\n`-Xno-param-assertions`).\n\n#### Which versions of Android does Kotlin support?\n\nAll of them! Kotlin is compatible with JDK 6, so apps with Kotlin safely run on\nolder Android versions.\n\n#### Where can I learn more about using Kotlin?\n\nCheck out [Additional resources for getting started with\nKotlin](/kotlin/getting-started-resources)."]]