avatar🐀
霂枯木霂枯木的小站

To witness the sunrise and the sea of blossoms.

行可兼知,而知不可兼行

Kotlin数据类型

整型 ​

Byte(8位)、Short(16位)、Int(32位)、Long(64位)

浮点型 ​

Float(32位)、Double(64位)

字符 ​

Char

字符串 ​

String

布尔 ​

Boolean

数组 ​

Array、IntArray、ByteArray、BooleanArray等

集合 ​

  • 不可变:List(有序)、Set(唯一)、Map(键值对)
  • 可变:MutableList、MutableSet、MutableMap

可空类型(Nullable Types) ​

  • 任何类型后加 ? 表示可空,如 String?
  • 处理空安全:?.、?:、!! 等操作符

特殊类型 ​

Unit:无返回值类型、 Nothing:永不返回(如总是抛出异常的函数)、 Nothing?:只包含 null 值的类型、 Any:非空根类、 Any?:包含空类、

类型别名(typealias) ​

为现有类型指定备选名称 typealias UserMap = Map<String, User>

函数类型 ​

val sum: (Int, Int) -> Int = { a, b -> a + b }

无符号整型 ​

溢出回绕

  1. UByte 8 位:0 ~ 255
  2. UShort 16 位:0 ~ 65,535
  3. UInt 32 位: 0 ~ 4,294,967,295 (约 42 亿)
  4. ULong 64 位: 0 ~ 18,446,744,073,709,551,615
Kotlin操作符
Hello, Valaxy!
由 Valaxy v1.2.0 驱动|主题-Yunv1.2.0