Android studio 3.0 native support kotlin example explanation

Although Android has become the first operating system of mobile devices, and its influence has also extended to cars and TV, it has always been a worry for Google to rely on Java for Android development, because Oracle is haggard because of the lawsuit between Java and Google on Android.

Now, Google officially supports kotlin https://kotlinlang.org/ , it has not been officially recognized as the first language for Android development, and starting from Android studio 3.0, kotlin will be directly integrated without installing any plug-ins. This language was invented by JetBrains last year. It is popular mainly because it runs on the Java virtual machine and can be used with java to build applications. This means that developers can use existing code to easily build new functions or replace java code. Because kotlin relies on Java, both languages will continue to be supported.

Google will be committed to promoting the development of kotlin related Android development tools to make it more efficient to use kotlin to develop Android applications. Of course, the ecosystem can not be created in a day. It will take time for kotlin to replace Java as the first language for Android development.

Let's do it

Suppose you have downloaded Android studio 3.0

1. To create a project, you must select include kotlin, or the default java development mode will be used

2. The next step, the next step and then completed (the first time will be a long time, because those libraries are basically abroad, you know)

The "findviewbyid" here can be omitted. Let's add another one in APP / build.gradle

Then the code can be written as

Any surprises? In fact, kotlin's extension feature is my favorite, so many tool classes can be omitted. For example, we add an extension method to view. Create a new kotlin file: viewex and add an extension function

Test:

Print out the results:

Is it convenient? You don't have to write any tool classes alone

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>