cool hit counter You should switch to Kotlin development_Intefrankly

You should switch to Kotlin development


Aandroid development are you still using java? Now is the time to start using a new programming language. Have you had your heart set on Kotlin since it became an official Google language?

I want to tell you about a new programming language called Kotlin and explain why you should consider using it in your next project. I used to really like using java, but when I used Kotlin myself last year, I really wouldn't be thinking about Java as a better choice (language-wise).

Kotlin isJetBrains Developed by the company. JetBrains actually developsIDES . for exampleIntelliJ harmonyReSharper . The real shine comes through Kotlin, which is simple and pragmatic, and makes coding a satisfying and effective experience.

Although Kotlin can compile JavaScript and machine code. But I'll focus on the initial environment (JVM)

So the following will give a few reasons why you need to switch to Kotlin language development (in no particular order)

I. Interoperability with Java

Kotlin is 100% interoperable with JAVA, which means you can use Kotlin to develop your old JAVA projects. All your favorite Java frameworks can continue to be used. And some of the Kotlin frameworks you've written can all serve your java friends lovers very easily too.

II. Familiar grammar

Kotlin is not a strange (and elusive language) in the academic (programming) world. programmers from the OOP (Object Oriented Programming Language) world are familiar with it. And more or less understandable. Of course there are some differences with Java. For example, a constructor, or a val, var variable declaration. (The following code snippet provides a partial description of the basics)

III. String Difference

It's like having a smarter, more readable version of Java built in.

IV. Type inference

Kotlin will infer the type you want (you will feel improved code readability)

V. Clever type conversions

The Kotlin compiler will keep track of your logic and do automatic type conversions, which means there won't be too much instanceof detection (in explicit conversions)

VI. Intuitive equivalence

You can stop using the equals() method to determine equality, because this operator will detect structural equality.

VII. Default parameters

Methods that do not require the definition of several similar parameters

VIII. Naming parameters

In combination with default parameters, named parameters eliminate constructors.

IX. when expressions

The switch statement is replaced with a more readable and flexible when expression.

Either as an expression or a statement, with or without arguments

X. Attributes

Public parameters of the customset&get behaviour, This means that we can stop our code from bloating(getters&setters bringing about)

XI. Data classes (similar to JavaBean)

A normal data bean (POJO) has toString(), equals(), hashCode(), and copy(), and does not exceed 100 lines of code like Java

XII. Operator Overloading

A set of predefined operators can be overloaded to improve readability

XIII. Destructuring Declarations

It is possible to deconstruct some objects, which is useful when iterating over a collection of data

XIV. Scope (Ranges)

Easy readability

XV. Extended methodology/functionality

Do you remember the first time you used sorting with List in Java? You can't find a sort method for sorting so you have to consult your teacher or look up google to get the method. Later when you use a String you might write a helper class to help you get what you want, because you don't know there

If there is only one way to add new functionality to an old class, then your IDE will help you find the appropriate functionality in your code, which is easy to do in Kotlin.

The standard library extends the functionality of Java's primitive types, which is what String specifically needs: the

XVI. Air safety

Java is a language that should be called almost statically typed, in Java, a variable of type String is not guaranteed to refer to String (safe) - it may refer to null, even if we are used to this type, it counteracts the safety of static type checking, so Java developers will not avoid to meet NPEs. (NullPointerException) or think of ways to avoid it (a bit more work than that)

Kotlin, on the other hand, solves this problem by distinguishing between non-empty types and empty types. By default, the type is non-null and a ? can be added by default. For example, the following:

When you access a null variable, Kotlin forces NPES(NullPointerException) to be avoided

Although this may seem a bit tedious, it really makes development easier because of these features and we can convert intelligently, converting empty types to non-empty types for our use.

And we can safely use it when we calculate a null (instead of throwing a null pointer exception)

The safe calls can be linked together to avoid the nested if-not-null checks we sometimes write in other languages, and if we want a default value other than non-null, we can use the elvis operator

If this doesn't apply to you and you need an NPE, you will have to explicitly ask for it

xvii. better lambda expressions

Good man, Kotlin has better support for Lambda, based on its smart and well-designed language, with a straightforward syntax and better readability and simplicity.

A better description is as follows

1. If the lambda expression is the last or only argument of the method, the method brackets can be moved or omitted

2. If we choose not to declare a single-argument-lambda, it will be implicitly declared as

From the above two points the following three lines of code form can be obtained.

And it also allows us to write cleaner and more beautiful code:

The perfect combination of Kotlin's lambda system features makes it ideal for DSL creation, check out Anko's DSL examples designed to serve Android development.

XVIII, IDE Support

If you plan to start using Kotlin, you have several options, but I highly recommend using the IntelliJ software that comes bundled with Kotlin.

As a small example, when I first tried to copy and paste some Java code from StackOverflow, this thing popped up .

Author: Wakan Bright Moon

links:http://www.jianshu.com/p/ec841df96f1e

original text address:Why you should totally switch to Kotlin

Technology - Thinking - Growing

END


Recommended>>
1、Data Scientist Eight Key Skills for Data Scientists
2、Installation of nodejs on windows and creation of helloworld miniapplication
3、Introduction to python crawler IV using multithreaded crawler
4、dbmslockrelase cant release a custom lock
5、简约而不简单大众点评小程序开发经验谈

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号