Programming/Kotlin

Kotlin Variable

Albothyl 2022. 4. 16. 10:25
  1. val
    1. 불변
    2. Getter 메소드만 제공
  2. var
    1. 가변
    2. Getter, Setter 메소드 제공
  3. val a: Int = 1  // immediate assignment
    val b = 2   // `Int` type is inferred
    val c: Int  // Type required when no initializer is provided
    c = 3       // deferred assignment. c에 값을 다시 할당하면 exception 발생