code A:
package main import "fmt" func main() { slice := IntSlice{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} fmt.Println(slice) } type IntSlice []int
pin A:
[0 1 2 3 4 5 6 7 8 9]
code B:
package main import "fmt" func main() { slice := IntSlice{0, 1, 2, 3, 4, 5, 6, 7, 8, 9} fmt.Println(slice) } type IntSlice []int func (slice IntSlice) Error() string { return "this is called." }
pin B:
this is called.
why is the behavior of fmt.Println(slice) different for these two codes (A and B)?
or why fmt.Println(slice) automatically calls slice.Error() ?
user6169399
source share