I'm trying to understand why the following test code is not working as expected:
package main
import (
"fmt"
"strings"
)
type Test struct {
someStrings []string
}
func (this Test) AddString(s string) {
this.someStrings = append(this.someStrings, s)
this.Count() // will print "1"
}
func (this Test) Count() {
fmt.Println(len(this.someStrings))
}
func main() {
var test Test
test.AddString("testing")
test.Count() // will print "0"
}
This would print:
"1"
"0"
Meaning that someStrings
is apparently modified... and then it's not.
Anybody know what could be the issue?