- Learn Kotlin Programming(Second Edition)
- Stephen Samuel Stefan Bocutiu
- 169字
- 2021-06-24 14:13:25
val and var
Kotlin has two keywords for declaring variables, val and var. The var variable is a mutable variable, that is, a variable that can be changed to another value by reassigning it. This is equivalent to declaring a variable in Java:
var name = "kotlin"
In addition to this, the var variable can be initialized later:
var name: String name = "kotlin"
Variables defined with var can be reassigned, since they are mutable:
var name = "kotlin" name = "more kotlin"
The val keyword is used to declare a read-only variable. This is equivalent to declaring a final variable in Java. A val variable must be initialized when it is created, since it cannot be changed later:
val name = "kotlin"
A read-only variable does not mean the instance itself is automatically immutable. The instance may still allow its member variables to be changed through functions or properties, but the variable itself cannot change its value or be reassigned to another value.
- Kali Linux Web Penetration Testing Cookbook
- Rust實戰
- Unity Virtual Reality Projects
- PHP+MySQL網站開發技術項目式教程(第2版)
- Mastering Scientific Computing with R
- 單片機應用與調試項目教程(C語言版)
- Web Development with MongoDB and Node(Third Edition)
- Android開發:從0到1 (清華開發者書庫)
- BeagleBone Black Cookbook
- Express Web Application Development
- ScratchJr趣味編程動手玩:讓孩子用編程講故事
- JavaScript從入門到精通(視頻實戰版)
- Drupal Search Engine Optimization
- Mastering Puppet(Second Edition)
- Kali Linux Wireless Penetration Testing Essentials