Home >Java >javaTutorial >Which one is better, Kotlin or JAVA?

Which one is better, Kotlin or JAVA?

PHP中文网
PHP中文网Original
2017-06-20 16:10:143248browse

Original link

Will Kotlin really replace JAVA?

Since Kotlin became the first-level language for Android development, Kotlin has indeed won the recognition of many overseas companies and developers for its practicality and efficiency. For example, Jake from Square has been promoting Kotlin. . Kotlin has at least nearly 2 years of practice in production environments abroad (non-JetBrains internal practice applications). In mobile development, compared to iOS programmers, Android programmers are always lucky because we have many excellent and easy-to-use tools (Android Studio, etc.). Choosing Kotlin is Google’s consistent commitment to providing developers with efficient development tools. style. Let’s first share some of the major features of Kotlin:

Kotlin is a statically typed programming language for modern multi-platform applications, 100% interoperable with Java™ and Android™ [java] view plain copy

Kotlin is a very simple 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 NullPointerExceptions, 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

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 to

import kotlin.browser.window

fun onLoad() {

window.document.body!! .innerHTML += "

Hello, Kotlin!"
}

Several community blog posts to help everyone better understand kotlin

-hello Kotlin

-Write Android programs with Kotlin

-Use Kotlin & Anko, throw away XML to develop Android applications

Then the question is

Have you started using and preparing to use Kotlin?

What do you think are the differences between Kotlin and JAVA, advantages or disadvantages?

Do you think Kotlin will replace JAVA?

The above is the detailed content of Which one is better, Kotlin or JAVA?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn