Today the Android team is excited to announce that we are officially adding
support for the Kotlin programming
language. Kotlin is a brilliantly designed, mature language that we believe will
make Android development faster and more fun. It has already been adopted by
several major developers — Expedia, Flipboard, Pinterest, Square, and others —
for their production apps. Kotlin also plays well with the Java programming
language; the effortless interoperation between the two languages has been a
large part of Kotlin's appeal.
The Kotlin plug-in is now bundled with Android Studio 3.0 and is available for
immediate download.
Kotlin was developed by JetBrains, the
same people who created IntelliJ,
so it is not surprising that the IDE support for Kotlin is outstanding.
In addition to the IDE support, we're announcing a collaboration with JetBrains
to move Kotlin into a non-profit foundation. (Kotlin is already open sourced
under Apache2.)
Modern. Expressive. Safe.
Just like Android, Kotlin is an open source project under Apache 2.0. Our choice of Kotlin reaffirms our commitment to an open developer ecosystem as we evolve and grow the Android platform, and we are excited to see the language evolve.Write safer code and avoid NullPointerExceptions in your app.
val name: String? = null // Nullable type
println(name.length()) // Compilation error
Kotlin on Android FAQ
The Android team took the liberty to answer some of the most pressing questions.Here are some of the questions and answers included in the FAQ.
Kotlin is fully supported in Android Studio 3.0 and higher. Previously, using Kotlin required that you add the Kotlin plugin, but all new releases of Android Studio ship with these tools built in. So you can create new projects with Kotlin files, convert Java language code to Kotlin, debug Kotlin code, and more, without any extra steps. See Get Started with Kotlin.
How do I debug Kotlin in Android Studio?
Debugging Kotlin works just like debugging Java code. You don’t need to do anything differently.
What kind of other IDE support is provided for Kotlin (like lint, autocomplete, refactorings, etc.)?
As of Android Studio 3.0, the IDE has full tooling support for Kotlin.
How do I choose between the Java and Kotlin languages?
You don’t have to pick! You can use both together as you see fit. If you need help discovering whether Kotlin is a good fit for you, you can try it on Android or learn more about the language with these Kotlin resources
Can I call Android or other Java language library APIs from Kotlin?
Yes. Kotlin provides Java language interoperability. This is a design that allows Kotlin code to transparently call Java language methods, coupled with annotations that make it easy to expose Kotlin-only functionality to Java code. Kotlin files that don’t use any Kotlin-specific semantics can be directly referenced from Java code without any annotations at all. Combined, this allows you to granularly mix Java code with Kotlin code. To learn more, seeKotlin’s interop documentation.
Can I use both Java files and Kotlin files in the same project?
Yes. You can adopt as much or as little Kotlin as you like and mix it with Java code using Kotlin’s interoperability with Java.
How do I add Kotlin to my new projects?
When you create a new project in Android Studio, just check the Include Kotlin support checkbox. For more information, see Get Started with Kotlin.
How do I add Kotlin to my existing projects?
Select your module in the Project window, and then select File > New, select any Android template, and then choose Kotlin as the Source language. For more information, see Get Started with Kotlin.
Will there be parallel docs, samples, codelabs, and templates in Kotlin?
We’re working to make our documentation and educational materials as useful as possible to both Java and Kotlin language users. In the meantime, developers can rely on Kotlin’s excellent interoperability with the Java language and the ability to automatically translate Java language code to Kotlin in Android Studio.
Do Kotlin coroutines work on Android? How about async/await?
Kotlin coroutines should currently work, but they are currently an experimental implementation. As such, Kotlin makes no guarantees about future status, and thus, neither does Android.
Which versions of Android does Kotlin support?
All of them! Kotlin is compatible with JDK 6, so apps with Kotlin safely run on older Android versions.
Hello Reader
You can comment if any confusion in syntax or if need more explanation we'll reply you ASAP.
Thank you Safe & Happy Coding. :)
No comments:
Post a Comment