At this year’s Google I/O 2017 developer conference, Google announced the inclusion of Kotlin as an official first-class language for Android applications. Kotlin, developed primarily by Russian team JetBrains, interconnects with Java but has features that Java does not support.

After hearing the news, friends are fried…

Well, if nothing else, what does this news mean for us?

Can’t use Kotlin?

You know, before Google got behind it, Kotlin was a wild card on Android, nobody approved of it, we had to take responsibility for it, and the code was handed over to us (most people didn’t want to learn it anyway).

Now you can say, wow, Kotlin is the official language, you don’t use it, you don’t want to use it, you will be forgotten in the history of the wheel print inside the small seam inside!

Want to use the Lambda?

One of the most exciting things about Kotlin’s early use of Android was the freedom to use Lambda, which was also supported (albeit weirdly) in Java 8, so Google sent someone to mess with Jack&Jill for two years. One day a guy walked in and shouted “Hi, Jack!” at the J&J developers. , and the project has been Deprecated. Well, Android developers will probably have to wait a long time for Lambda to be available on Google, and at the same time, it will probably have to wait until some version of the API is available, which is awkward.

Who can save you? Kotlin, of course! Functions are first-class citizens of Kotlin, support functional programming is no pressure, Lambda experience not to mention, oh, no, I’m going to write Kotlin ~

Want to use a Coroutine?

The Camera API has recently been wrapped. If you have used Camera, you must know that Camera has two sets of apis. The old API is basically a synchronous call interface, and only Camera and diagonal have callbacks. With the new API, all instructions are sent asynchronously, like HTTP requests, and callbacks run on the same thread as one of the handlers we passed in when we made the request.

I was desperate when I came across an API like this.

There are a lot of ways to write callback sleeves in development. How do you write a piece of code that looks like it executes synchronously, but actually handles the asynchronous request itself? Coroutine, of course.

Those of you who have developed Unity will certainly think of this. Last year, a colleague of mine worked on the game for a while and was impressed with the use of Coroutine. What are its main advantages?

  • The code looks straightforward and easy to understand

  • Exception handling is simple (a try… Catch the problem

  • Low resource consumption (Coroutine is very economical compared to having ten or eight thread pools all the time)

Ok, so what’s the key? In Kotlin 1.1, Coroutine has been very improved, although it is still labeled Experimental, but Kotlin 1.2 will not change the visual, think of the future Android code will have such things, really feel the world is beautiful!

Oh, no! I’m going to write about Kotlin!

WTFUtils

Bring it up every time. Your code must have piles of StringUtils/ImageUtils/BitmapUtils/LogUtils such a thing!

Everyone has their own LogUtils, although some people use LogUtil. As a result, WHEN I type LogUti in as double-shift, I get a bunch of LogUti.

There was once a group of iOS big brother to share, “Hand in hand to teach Android development to write iOS”, which specifically mentioned the feature of dynamic modification method, as well as the feature of extension method, Emma, look at my eyes, I want to someday I can also add some util method to String, The more good.

Then I met Kotlin, Android guys. Go ahead, delete your XXUtils or XXUtil and let those memories go.

Null pointer exception?

I heard that Android code written in Java often produces null pointer exceptions. Is it half a month of hard work, a run on thousands of times? Thousands of times, but also every time is that empty pointer, anxious you straight tears off, ah, this TM is what broken logic, template code countless, check check meng force.

Kotlin, a safe type to help you, is never afraid of null Pointers.

.

Haha, I’m going to write Kotlin, don’t get in my way.

reading

  • Why do you need Kotlin

  • Why Kotlin is Worth a try




If you think our content is good, please forward it to moments and share it with your friends