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