我是Golang的新手。很抱歉,我仍然对以下两者之间的区别感到困惑:
type <Name> <dataType>
和
type <Name> = <dataType>
这是一个例子:
package main
import "fmt"
func main() {
var (
strWord Word
strText Text
)
strWord = "gopher"
strText = "golang"
fmt.Printf("strWord = %s, Type of Value = %T\n", strWord, strWord)
fmt.Printf("strText = %s, Type of Value = %T\n", strText, strText)
}
type Word string
type Text = string
输出
strWord = gopher, Type of Value = main.Word
strText = golang, Type of Value = string
那么,我们什么时候应该在两者之间使用?