- Hands-On Design Patterns with Kotlin
- Alexey Soshin
- 87字
- 2021-06-25 20:49:23
val versus var
In Java, variables can be declared final. Final variables can be assigned only once:
final String s = "Hi";
s = "Bye"; // Doesn't work
Kotlin urges you to use immutable data as much as possible. Final variables in Kotlin are simply val:
val s = "Hi"
s = "Bye" // Doesn't work
If you do have a case in which you would like to reassign a variable, use var instead:
var s = "Hi"
s = "Bye" // Works now
推薦閱讀
- CMDB分步構建指南
- Python數據分析基礎
- Developing Mobile Web ArcGIS Applications
- 薛定宇教授大講堂(卷Ⅳ):MATLAB最優化計算
- Kinect for Windows SDK Programming Guide
- Access 2016數據庫管
- Learning Python by Building Games
- ASP.NET程序設計教程
- Learning Vaadin 7(Second Edition)
- 程序設計基礎教程:C語言
- Creating Stunning Dashboards with QlikView
- App Inventor創意趣味編程進階
- Android應用開發實戰
- Python Machine Learning Blueprints:Intuitive data projects you can relate to
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)