官术网_书友最值得收藏!

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
主站蜘蛛池模板: 南漳县| 绍兴市| 甘泉县| 崇州市| 瑞安市| 星座| 井冈山市| 区。| 柯坪县| 福鼎市| 中宁县| 山东| 威信县| 玛纳斯县| 汉沽区| 丰都县| 神木县| 秭归县| 宣化县| 区。| 扶沟县| 宁国市| 黄山市| 乌兰察布市| 景谷| 黄石市| 东丰县| 清涧县| 拜泉县| 蒲江县| 仙居县| 白河县| 灯塔市| 新乐市| 洪雅县| 东阿县| 卓尼县| 罗江县| 平武县| 舞钢市| 高阳县|