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
output 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." }
output B:
this is called.
why the behavior of fmt.Println(slice)
is different for these two codes( A and B)?
or why fmt.Println(slice)
calls slice.Error()
automatically?