What
静态类型编程语言
多平台:支持JVM平台,Android平台,浏览器JS,本地机器码等平台
与Java,Android 100%互通
Kotlin是:
- 一种运行在Java虚拟机上静态类型编程语言
- 可以被编译成为JavaScript源代码
- 在没有JVM执行环境的平台上,比如 iOS, 嵌入式平台,可以使用Kotlin-Native(https://github.com/JetBrains/kotlin-native), 直接把Kotlin代码编译成本地机器码。
目标
- 创建一种兼容 Java 的语言
- 让它比 Java 更安全,能够静态检测常见的陷阱。如:引用空指针
- 让它比 Java 更简洁,通过支持 variable type inference,higher-order functions (closures),extension functions,mixins and first-class delegation 等实现
- 让它比最成熟的竞争对手 Scala语言更加简单
Why
- 调高开发效率
- 兼容多种平台
- 利用已有的库
Kotlin声称 100% interoperable with Java。Kotlin 能与 Java 混合使用,并且直接复用 Java 的生态系统(库、框架、工具)。一个已有的 Java 项目,只需引用 Kotlin 的 Maven/Gradle 插件,以及引用 Kotlin 标准库的依赖,就可以逐渐掺入 Kotlin 代码。你完全可以当它是 A Better Java 。
Kotlin基本特性
- 运行于JVM (Java Virtual Machine)上的语言,直接继承JVM生态所有成就
- 静态类型,即变量类型是编译时确定的
- 函数式的编程语言:
- 函数是一等公民: 函数既可以是变量,也可以当做参数传给另外一个函数。
- 不可变对象: 不可变对象的状态,运行时保持不变。
- 无副作用: 使用纯函数,不管执行多少次,针对相同输入,每次输出都一致。
- 支持面向对象编程(OOP,Object-Oriented Programming)。
- 完全开源
- Kotlin是静态类型的语言,也可以编程成Java字节码以及JavaScript,作为一个时髦又表现丰富的编程语言,Kotlin就是被设计用来生 产高性能要求的程序的,所以运行起来和Java也是不相上下
- Kotlin的定位非常有特点,它并不像是scala另起炉灶,将类库,尤其是集合类都自己来了一遍.
- Kotlin是对现有Java的增强,通过扩展方法给java提供了很多诸如fp之类的特性,但同时始终保持对Java的兼容. 这是Kotlin官网首页重点强调的:
Application
Using Kotlin for Server-side Development
Kotlin is a great fit for developing server-side applications, allowing to write concise and expressive code while maintaining full compatibility with existing Java-based technology stacks and a smooth learning curve:
- Expressiveness: Kotlin's innovative language features, such as its support for type-safe builders and delegated properties, help build powerful and easy-to-use abstractions.
- Scalability: Kotlin's support for coroutines helps build server-side applications that scale to massive numbers of clients with modest hardware requirements.
- Interoperability: Kotlin is fully compatible with all Java-based frameworks, which lets you stay on your familiar technology stack while reaping the benefits of a more modern language.
- Migration: Kotlin supports gradual, step by step migration of large codebases from Java to Kotlin. You can start writing new code in Kotlin while keeping older parts of your system in Java.
- Tooling: In addition to great IDE support in general, Kotlin offers framework-specific tooling (for example, for Spring) in the plugin for IntelliJ IDEA Ultimate.
- Learning Curve: For a Java developer, getting started with Kotlin is very easy. The automated Java to Kotlin converter included in the Kotlin plugin helps with the first steps. Kotlin Koans offer a guide through the key features of the language with a series of interactive exercises
Frameworks for Server-side Development with Kotlin
-
Spring makes use of Kotlin's language features to offer more concise APIs, starting with version 5.0. The online project generator allows to quickly generate a new project in Kotlin.
-
Vert.x, a framework for building reactive Web applications on the JVM, offers dedicated support for Kotlin, including full documentation.
-
Ktor is a framework built by JetBrains for creating Web applications in Kotlin, making use of coroutines for high scalability and offering an easy-to-use and idiomatic API.
-
kotlinx.html is a DSL that can be used to build HTML in a Web application. It serves as an alternative to traditional templating systems such as JSP and FreeMarker.
-
The available options for persistence include direct JDBC access, JPA, as well as using NoSQL databases through their Java drivers. For JPA, the kotlin-jpa compiler plugin adapts Kotlin-compiled classes to the requirements of the framework.
Ref:
官网:https://www.kotlincn.net/
网友评论