ThinkSSL🔒 一键申购 5分钟快速签发 30天无理由退款 购买更放心 广告
# 与 Java 语言比较 [TOC] ## Kotlin 解决了一些 Java 中的问题 Kotlin 通过以下措施修复了 Java 中一系列长期困扰我们的问题: * 空引用由[类型系统控制](http://www.kotlincn.net/docs/reference/null-safety.html)。 * [无原始类型](http://www.kotlincn.net/docs/reference/java-interop.html) * Kotlin 中数组是[不型变的](http://www.kotlincn.net/docs/reference/basic-types.html#%E6%95%B0%E7%BB%84) * 相对于 Java 的 SAM-转换,Kotlin 有更合适的[函数类型](http://www.kotlincn.net/docs/reference/lambdas.html#%E5%87%BD%E6%95%B0%E7%B1%BB%E5%9E%8B) * 没有通配符的[使用处型变](http://www.kotlincn.net/docs/reference/generics.html#%E4%BD%BF%E7%94%A8%E5%A4%84%E5%9E%8B%E5%8F%98%E7%B1%BB%E5%9E%8B%E6%8A%95%E5%BD%B1) * Kotlin 没有受检[异常](http://www.kotlincn.net/docs/reference/exceptions.html) ## Java 有而 Kotlin 没有的东西 * [受检异常](http://www.kotlincn.net/docs/reference/exceptions.html) * 不是类的[原生类型](http://www.kotlincn.net/docs/reference/basic-types.html) * [静态成员](http://www.kotlincn.net/docs/reference/classes.html) * [非私有化字段](http://www.kotlincn.net/docs/reference/properties.html) * [通配符类型](http://www.kotlincn.net/docs/reference/generics.html) * [三目操作符 `a ? b : c`](control-flow.html#if-表达式) ## Kotlin 有而 Java 没有的东西 * [Lambda 表达式](http://www.kotlincn.net/docs/reference/lambdas.html) + [内联函数](http://www.kotlincn.net/docs/reference/inline-functions.html) = 高性能自定义控制结构 * [扩展函数](http://www.kotlincn.net/docs/reference/extensions.html) * [空安全](http://www.kotlincn.net/docs/reference/null-safety.html) * [智能类型转换](http://www.kotlincn.net/docs/reference/typecasts.html) * [字符串模板](http://www.kotlincn.net/docs/reference/basic-types.html#%E5%AD%97%E7%AC%A6%E4%B8%B2) * [属性](http://www.kotlincn.net/docs/reference/properties.html) * [主构造函数](http://www.kotlincn.net/docs/reference/classes.html) * [一等公民的委托](http://www.kotlincn.net/docs/reference/delegation.html) * [变量与属性类型的类型推断](http://www.kotlincn.net/docs/reference/basic-types.html) * [单例](http://www.kotlincn.net/docs/reference/object-declarations.html) * [声明处型变 & 类型投影](http://www.kotlincn.net/docs/reference/generics.html) * [区间表达式](http://www.kotlincn.net/docs/reference/ranges.html) * [操作符重载](http://www.kotlincn.net/docs/reference/operator-overloading.html) * [伴生对象](http://www.kotlincn.net/docs/reference/classes.html#%E4%BC%B4%E7%94%9F%E5%AF%B9%E8%B1%A1) * [数据类](http://www.kotlincn.net/docs/reference/data-classes.html) * [分离用于只读与可变集合的接口](http://www.kotlincn.net/docs/reference/collections-overview.html) * [协程](http://www.kotlincn.net/docs/reference/coroutines.html)