In this bizarre example, someone has created a new type which is really just a string:
type CustomType string
const (
Foobar CustomType = "somestring"
)
func SomeFunction() string {
return Foobar
}
However, this code fails to compile:
cannot use Foobar (type CustomType) as type string in return argument
How would you fix SomeFunction so that it is able to return the string value of Foobar ("somestring") ?
question from:
https://stackoverflow.com/questions/45891600/converting-a-custom-type-to-string-in-go 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…