- 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.
- Vue.js 3.x快速入門
- Java程序設計(慕課版)
- C語言程序設計基礎與實驗指導
- Learn Programming in Python with Cody Jackson
- Practical Game Design
- Hands-On Natural Language Processing with Python
- Python之光:Python編程入門與實戰
- Mastering Web Application Development with AngularJS
- 搞定J2EE:Struts+Spring+Hibernate整合詳解與典型案例
- Android傳感器開發與智能設備案例實戰
- Penetration Testing with the Bash shell
- Python GUI Programming Cookbook(Second Edition)
- JavaWeb從入門到精通(視頻實戰版)
- Learning Ionic(Second Edition)
- 數據結構與算法詳解