[]string, []string){
newSlice := make([]string, 0, n)
for := 0; i < n; i++ {
newSlice = append(newSlice, „test“)
}
return newSlice, newSlice
}
func main() {
// From now on, list is immutable, because return value is immutable
list, _ := CreateSlice(10)
list = append(list, „another one“) // Compile-time error
}
Better tell me how this would not work?
Обсуждают сегодня