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
?
感謝