首页 > Java > java教程 > 正文

Kotlin与JAVA到底哪个好?

PHP中文网
发布: 2017-06-20 16:10:14
原创
3574人浏览过

原文链接

Kotlin真的会取代JAVA吗?

自从Kotlin 成为 Android 开发一级语言,Kotlin确实以其实用,高效赢得了海外很多公司和开发者的认可,比如Square的Jake大神一直在推Kotlin。Kotlin在国外至少有将近2年的应用生产环境的实践(非JetBrains内部实践应用)。在移动开发中,相比iOS程序员,Android程序员总是很幸运,因为我们有很多优秀好用的工具(Android Studio等),选用Kotlin,则是Google 为开发者提供高效的开发工具的一贯作风。先来晒一晒Kotlin的几大特点:

Kotlin是静态类型编程语言,用于现代多平台应用,100%可与Java™和Android™互操作 [java] view plain copy

Kotlin是非常简介的编程语言

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:

立即学习Java免费学习笔记(深入)”;

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

object ThisIsASingleton {
val companyName: String = "JetBrains"
}

[java] view plain copy

Kotlin 很安全

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

Ai好记
Ai好记

强大的AI音视频转录与总结工具

Ai好记 311
查看详情 Ai好记

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

方便使用 兼容JVM上现有library

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!"
}

几篇社区的博文帮助大家更好的了解kotlin

-hello Kotlin

-用Kotlin写Android程序

-使用Kotlin&Anko,扔掉XML开发Android应用

那么问题来了

你是否已经开始使用准备使用Kotlin?

你觉得Kotlin与JAVA之间的区别有哪些,优势or缺点?

你觉得Kotlin会取代JAVA吗?

以上就是Kotlin与JAVA到底哪个好?的详细内容,更多请关注php中文网其它相关文章!

相关标签:
java速学教程(入门到精通)
java速学教程(入门到精通)

java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号