Kotlin language introductory book | Android Developers FAQ Vol.5

With the rapid emergence of Kotlin, we note that more and more developers started to pay attention to this new language. This issue "Googel Play Developer FAQ", we launched a special Kotlin language topics, hope this will help you better understand the characteristics and development status of Kotlin language, and try to use Kotlin language for Android development.

Why do we want to use Android as the best support Kotlin language?

Kotlin as Android supported development languages, with characteristic simplicity, powerful and the type and null pointer security. It fusion work with the Java language perfectly, so that makes those who love Java developers can continue to use the Java language, while adding additional code, and use code libraries Kotlin Kotlin language. In addition, many Android developers have found that the use Kotlin develop faster and lots of fun, so we decided to better support these developers. You can read more instructions on Kotlin and Android in our official documentation.

It took me a long time ago Kotlin, are there any changes?

We launched the Android Studio 3.0 and later versions, it contains the full support of Kotlin. This will bring easier, more stable development experience.

What are the benefits using Kotlin development?

Articulate, concise, and strong expansion

Type safety

Null pointer security

And JAVA, C ++ seamless

So we did a better support for developers to use Kotlin, if you are interested in Kotlin, you first need to upgrade to the 3.0 version of Android Stuido, Kotlin tools directly tied to this version of them. If you have problems in use, please refer to "Kotlin FAQ's Android Studio" at the following link

(https://developer.android.google.cn/studio/preview/kotlin-issues.html)

How to use Kotlin In Android Studio?

You can easily create Android Studio 3.0 on a Kotlin project file, convert Java language Kotlin language, and continue to use your familiar Andoid Studio tools such as autocomplete, lint checker, refactoring, debugging and so on.

Create a project that contains the Kotlin

In Android Studio, click "File> New> New Project".

In the initial page, click Include Kotlin support

Click Next to continue until your project is created

After such an Activity template is selected, the source code will be provided in the form of Kotlin code, but only some of the phone or tablet template code provides Kotlin code is native, and the rest will only be converted from the Java code that could and the best feature of Kotlin language is not used.

How to Debug Kotlin In Android Studio?

In the Debug aspect, you can, as before Debug Java to debug your application.

What other IDE provides support for Kotlin? (Such as Link, autocomplete, refactoring, etc.)

On Android Stuido 3.0, Kotlin provides support for all the tools, if you find a problem in use, please refer to the following link in the "Kotlin interoperability document."

(https://kotlinlang.org/docs/reference/java-interop.html)

Kotlin in the future direction of development?

One reason is because we use Kotlin at JetBrains in the design of the language is very attentive and working instructive. Google and Kotlin Kotlin cooperation to ensure that the use of the process is a complete and wonderful story - from the language, the tool frame. We are very pleased that such cooperation can become a tool for Kotlin a non-profit to for the majority of developers use.

Kotlin is open source it?

On Kotlin, our preferred open-source agreement is "the Apache Software License, Version 2.0" ( http://www.apache.org/licenses/LICENSE-2.0 ) "the Apache 2.0."

The main Kotlin and software are used in Apache 2.0. Although Kotlin project will follow this agreement, but there may be exceptional circumstances there will be special treatment. For example, some third-party libraries used Kolint may use other open source license compatible with the Apache 2.0.

How should I choose between Kotlin and Java?

You do not have to worry about this problem, you can use the two together, if you want to know if Kotlin apply to you, or you can try to learn more about Kotlin language information on Android.

Documents:

" Kotlinlang.org " ( https://kotlinlang.org/ ) Kotlin's official website, contains all of the "basic grammar" ( https://kotlinlang.org/docs/reference/basic-syntax.html ) and "Standard library reference "( https://kotlinlang.org/api/latest/jvm/stdlib/index.html )

"Kotlin koans Online" ( https://try.kotlinlang.org/ ) online IDE in a series of exercises to help you learn grammar Kotlin

video:

△ "Introduction to Kotlin" describes Kotlin Google I / O 2017 conference as the official language support

"O'Reilly Course," ( http://shop.oreilly.com/product/0636920052982.do ) Kotlin an 8-hour course, lecturers of the video is the developer of the company JetBrains Hadi Hariri, introduced Kotlin programming design. You need to buy a subscription, 7-day free trial.

“Treehouse course” (https://teamtreehouse.com/library/kotlin-for-java-developers)

"Udemy Course," ( https://www.udemy.com/kotlin-course/ ) "Kotlin beginner", taught from scratch, you need to purchase a subscription, beginners have a discount.

books:

"Kotlin in Action" ( https://www.manning.com/books/kotlin-in-action ): written by Kotlin at JetBrains Developer Dmitry Jemerov and Svetlana Isakova

"Kotlin for Android Developers" ( https://leanpub.com/kotlin-for-android-developers one) Kotlin earliest books, written by Antonio Leiva

Social channels:

"Kotlin Community Community" ( https://kotlinlang.org/community/ ) kotlinlang.org community projects under the line with the group

"Kotlin Slack" ( http://slack.kotlinlang.org/ ) Kotlin user community discussion

"Kotlin at Talking" ( http://talkingkotlin.com/ ) Kotlin of fortnightly blog

I can call other Android or Java language libraries do in Kotlin in?

Kotlin provides interoperability of the Java language, which means Kotlin file, you can not specify the annotation or Kotlin language meaning, you can call Java methods directly in Kotlin inside, which means that your Java programs can coexist and Kotlin code .

Can I use it in C ++ using the Kotlin?

Of course you can, JNI fully support the Kotlin.

To call native C or C ++ code, just ahead of the use of external modifier to mark what you can:

external fun foo(x: Int): Double

How I add Kotlin file in an existing project?

If you want the project to be added to existing Kotlin, click "File> New" to select a template. If you do not see this menu, you need to first open the Project window and select your app components.

When the configuration wizard appears, select "Source Language" select "Kotlin"

As for the other way, you can go to create a basic file via "File> New> Kotlin File / Class", "New Kotlin File / Class" window offers a choice of some documents, because after you change the type, Kotlin will automatically convert file types, so what you choose is not important.

Kotlin file is saved in "src / main / java /", you'll find Kotlin files and Java files in one folder inside, but if you want to separate your Kotlin files and Java files, you can use the "src / main / kotlin / "instead, if you need to do this, just add the following statement in your configuration on it.

Android {

sourceSets {

main.java.srcDirs += ‘src/main/kotlin’

}

}

How do I convert Java code into Kotlin Code?

In Android Studio 3.0, open a Java file and select "Code> Convert Java File to Kotlin File".

Kotlin or create a file "(File> New> Kotlin File / Class)", and then copy your Java code to Kotlin file. When there is the prompt that appears, click "Yes" to convert Java code Kotlin code, and you can check the "Do not show this dialog next time" to facilitate your next conversion.

For Kotlin will provide (the same Java) complete the corresponding documentation, code and templates do?

We're working on our documentation, code templates as much as possible while covering Java and Kotlin. At the same time, developers can rely on Java and Kotlin interoperability convert Java code in Android Studio Kotlin Code.

How about Kotlin coroutine use on Android? How asynchronous, waiting for other operations?

Kotlin coroutine should now be available, but because of Kotlin of this mechanism is still in the experimental design stage, Kotlin will not have any guarantee of the future state, Android will not be the same.

Kotlin APK will affect the size of it? Affects the number of ways?

Kotlin may increase the 7000 method and the size of 1M in your debug APK at runtime, if you use other libraries such as Kotlin replace Guava, RxJava, etc., the impact could be smaller. But you can be optimized to reduce the size of the package by ProGuard late.

Use Kotlin will have any affect performance?

There is no direct impact on the performance of Kotlin. But it Like Java, performance, and performance is closely related to your use.

For example: In multiple collection instances, duplicate copy operation will affect GC performance, calling a non-empty type of method accepted will add a blank check method invocation (but you can be disabled by setting -Xno-param-assertions run null pointer compile-time checking)

Which version supports Kotlin?

Kotlin is compatible with Java 6.0, so you can safely use Kotlin on all Android versions.

These are related to the current entry Kotlin language Developer FAQ, and if you have additional questions, please give us feedback through mail.

  Dalian Bohai Hospital bpmobile.39552222.com

  Dalian Bohai Hospital, mobile.bhnkyy.net

Guess you like

Origin blog.csdn.net/qq_42894764/article/details/93618566