Does Kotlin replace JAVA ?, Replacing JAVA with Kotlin

Source: Internet
Author: User

Does Kotlin replace JAVA ?, Replacing JAVA with Kotlin

Original article link

Does Kotlin replace JAVA? Release date: 13: 36: 061019 followers 59

Since Kotlin became a top-level Android development language, Kotlin has been used in real time and has won the recognition of many overseas companies and developers. For example, the great god of Square has been pushing Kotlin. Kotlin has at least two years of application production environment practice abroad (non-JetBrains internal practice application ). Compared with iOS programmers, Android programmers are always lucky in mobile development, because we have many excellent and useful tools (such as Android Studio) and choose Kotlin, it is Google's consistent style of providing efficient development tools for developers.

Let's take a look at the features of Kotlin:
Kotlin is a static programming language for modern multi-platform applications. It can interwork with Java and Android in 100% [java] view plain copy

Kotlin is a very brief programming language.

Create a POJO with getters, setters, equals (), hashCode (), toString () and copy () in a single line:

Data class Customer (val name: String, val email: String, val company: String)
Or filter a list using a lambda expression:

Val positiveNumbers = list. filter {it> 0}
Want a singleton? Create an object:

Object ThisIsASingleton {
Val companyName: String = "JetBrains"
}

[Java] view plain copy

Kotlin is safe.

Get rid of those pesky nullpointertions, you know, The Billion Dollar Mistake

Var output: String
Output = null // Compilation error
Kotlin protects you from mistakenly operating on nullable types

Val name: String? = Null // Nullable type
Println (name. length () // Compilation error
And if you check a type is right, the compiler will auto-cast it for you

Fun calculateTotal (obj: Any ){
If (obj is Invoice)
Obj. calculateTotal ()
}

[Java] view plain copy

Easy to use and compatible with existing libraries on JVM

Use any existing library on the JVM, as there's 100% compatibility, including SAM support.

Import io. reactivex. Flowable
Import io. reactivex. schedulers. Schedulers

Flowable
. FromCallable {
Thread. sleep (1000) // imitate expensive computation
"Done"
}
. SubscribeOn (Schedulers. io ())
. ObserveOn (Schedulers. single ())
. Subscribe (: println, Throwable: printStackTrace)
Target either the JVM or JavaScript. Write code in Kotlin and decide where you want to deploy

Import kotlin. browser. window

Fun onLoad (){
Too many Doc ument. body !!. InnerHTML + ="
Hello, Kotlin! "
}

Several Community blog posts help you better understand kotlin-hello Kotlin-use Kotlin to write Android programs-use Kotlin & Anko, throwing away XML to develop Android applications, the question is: have you started using Kotlin? What are the differences between Kotlin and JAVA, advantages or disadvantages? Do you think Kotlin will replace JAVA?

 

Original article link

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.