这是我的戈朗代码package testimport ( "fmt" "testing")func TestOne(t *testing.T) { bytes := make([]byte, 0) bytes = append(bytes, 1, 2, 3) // pass bytes = append(bytes, []byte{1, 2, 3}...) // pass bytes = append(bytes, "hello"...) // pass too, ok. reference: As a special case, it is legal to append a string to a byte slice}func TestTwo(t *testing.T) { printBytes([]byte{1, 2, 3}...) // pass printBytes("abcdefg"...) // fail}func printBytes(b ...byte) { fmt.Println(b)}这些是strings.Builderfunc (b *Builder) WriteString(s string) (int, error) { b.copyCheck() b.buf = append(b.buf, s...) return len(s), nil}在函数 中使用该参数时,可以将其视为类型。ssliceappend但是我定义了一个函数,如,printBytesappend当我像这样调用时printBytes("abcdefg"...)似乎不被视为一种类型"abcdefg"slice
添加回答
举报
0/150
提交
取消