如果我有此代码,它将按预期工作:
package main
import "strconv"
type text []byte
func main() {
hello := text("hello")
_ = strconv.AppendQuote(hello, " world")
}
但这段代码失败了:
package main
import "strconv"
type text string
func main() {
hello := text("hello")
// cannot use hello (type text) as type string in argument to strconv.Quote
_ = strconv.Quote(hello)
}
为什么一个通过,另一个失败?我检查了文档 [1],但没有看到任何解释差异的内容。
https://go.dev/ref/spec#Type_definitions
喵喔喔
开心每一天1111
子衿沉夜
相关分类