- 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.
- Cocos2D-X權(quán)威指南(第2版)
- LabVIEW 2018 虛擬儀器程序設(shè)計(jì)
- Python 深度學(xué)習(xí)
- Java EE框架整合開發(fā)入門到實(shí)戰(zhàn):Spring+Spring MVC+MyBatis(微課版)
- ASP.NET Core Essentials
- Android Application Development Cookbook(Second Edition)
- 精通軟件性能測(cè)試與LoadRunner實(shí)戰(zhàn)(第2版)
- 小程序,巧運(yùn)營(yíng):微信小程序運(yùn)營(yíng)招式大全
- SQL Server 2016數(shù)據(jù)庫(kù)應(yīng)用與開發(fā)習(xí)題解答與上機(jī)指導(dǎo)
- Mastering Predictive Analytics with Python
- 零基礎(chǔ)學(xué)單片機(jī)C語(yǔ)言程序設(shè)計(jì)
- bbPress Complete
- Python時(shí)間序列預(yù)測(cè)
- Visual Basic程序設(shè)計(jì)實(shí)驗(yàn)指導(dǎo)(第二版)
- Dart:Scalable Application Development