- 优点
- 命令
- kotlinc
- -include-runtime 编译进kotlin运行库,从而可以直接运行
- kotlinc-jvm
- 场景
- 编译java执行
- kotlinc hello.kt -include-runtime -d hello.jar
- java -jar hello.jar
- 编译kotlin执行
- kotlinc hello.kt -d hello.jar
- kotlin -classpath hello.jar HelloKt
- 脚本语言使用
- 数据类型
- Double
- Float
- Long
- Int
- Short
- Byte
- 类
-
class Runoob() {
// 构造函数
init {
println("FirstName is $firstName")
}
// 次构造函数
constructor(parent: Person) {
parent.children.add(this)
}
var no: Int = 100
get() = field
set(value) {
}
fun foo() { print("Foo") }
}
- 语法
- NULL检查
- var age: String? = “23”
- val ages = age!!.toInt()
- val ages1 = age?.toInt()
- val ages2 = age?.toInt() ?: -1