最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

kotlin 為什么構(gòu)造函數(shù)的參數(shù)可以加上var val修飾,而普通函數(shù)就不行呢?

kotlin 為什么構(gòu)造函數(shù)的參數(shù)可以加上var val修飾,而普通函數(shù)就不行呢?

狐的傳說(shuō) 2018-10-05 09:19:46
kotlin 為什么構(gòu)造函數(shù)的參數(shù)可以加上var val修飾,而普通函數(shù)就不行呢?
查看完整描述

2 回答

?
Qyouu

TA貢獻(xiàn)1786條經(jīng)驗(yàn) 獲得超11個(gè)贊

早期的 Kotlin 版本函數(shù)參數(shù)是可以定義成 var 的,不過(guò)后來(lái)官方明確了「函數(shù)參數(shù)都是不可變」這一點(diǎn)。在這篇更新日志里可以找到說(shuō)明:

The main reason is that this was confusing: people tend to think that
this means passing a parameter by reference, which we do not support
(it is costly at runtime). Another source of confusion is primary
constructors: “val” or “var” in a constructor declaration means
something different from the same thing if a function declarations
(namely, it creates a property). Also, we all know that mutating
parameters is no good style, so writing “val” or “var” in front of a
parameter in a function, catch block of for-loop is no longer allowed.


查看完整回答
反對(duì) 回復(fù) 2018-10-21
  • 2 回答
  • 0 關(guān)注
  • 2692 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)