package main type S1 struct {i int; j int} func (s *S1) Inc() int { t := s.i s.i += 66 assert(s.i - t == 66) return s.i } func (s S1) Inc2() int { assert(s.j == 0) s.j += 1 assert(s.j == 1) return s.j } func typeAssert() { var i interface{} = "hello" s, ok := i.(string) assert(ok) assert(s == "hello") s1 := i.(string) assert(s1 == "hello") var j interface{} = "h" s, ok = j.(string) assert(ok) assert(s == "h") var k interface{} _, ok = k.(string) assert(!ok) } type Add func(a int, b int) int func main() { type S2 struct {i int} var s1 S1 //var s2 S2 s1.Inc() s1.Inc2() assert(s1.i == 66) assert(s1.j == 0) p := &s1.i *p = 5 assert(s1.i == 5) assert(s1.i == *p) f := s1.Inc f() assert(s1.i == 71) var afunc Add = func(i int, j int) int { return i + j + 1} d := afunc(s1.i, s1.j) assert(d == s1.i + s1.j + 1) typeAssert() typeAssert() typeAssert() } // 3, 8, 9