- 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.
- Programming ArcGIS 10.1 with Python Cookbook
- 從0到1:HTML+CSS快速上手
- SQL Server 2016數(shù)據(jù)庫(kù)應(yīng)用與開(kāi)發(fā)習(xí)題解答與上機(jī)指導(dǎo)
- Ext JS 4 Web Application Development Cookbook
- Mastering Apache Spark 2.x(Second Edition)
- Java Web程序設(shè)計(jì)任務(wù)教程
- Go語(yǔ)言精進(jìn)之路:從新手到高手的編程思想、方法和技巧(2)
- 小程序,巧應(yīng)用:微信小程序開(kāi)發(fā)實(shí)戰(zhàn)(第2版)
- .NET Standard 2.0 Cookbook
- IBM Cognos TM1 Developer's Certification guide
- C指針原理揭秘:基于底層實(shí)現(xiàn)機(jī)制
- 測(cè)試工程師Python開(kāi)發(fā)實(shí)戰(zhàn)
- 鋁合金陽(yáng)極氧化與表面處理技術(shù)(第三版)
- HTML5 and CSS3:Building Responsive Websites
- Lync Server Cookbook