1
假设我有两个文件。如何在两种自定义类型之间进行投射
hello.go
package main
type StringA string
func main() {
var s StringA
s = "hello"
s0 := s.(StringB) <---- somehow cast my StringA to StringB. After all, they are both strings
s0.Greetings()
}
bye.go
package main
import "fmt"
type StringB string
func (s StringB) Greetings(){
fmt.Println(s)
}
和编译该是这样的:
go build hello.go bye.go
如何投StringA
的类型StringB
?
感谢