這兩個Golang函式有什么不同,它們彼此相同嗎?
func foo1() (ret string) {
ret = "hi there"
return
}
func foo2() string {
ret := "hi there"
return ret
}
哪個更好?
uj5u.com熱心網友回復:
這兩個函式是相同的:https : //go.dev/play/p/_6KT5thL2Sj
foo2使用隱式回傳。foo1使用命名的回傳值并naked/bare回傳。有些人認為這是代碼異味:建議:Go 2:洗掉裸回傳
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/404474.html
標籤:
