在下面的语法_1中,
Compare-Object
和语法_2,
array := [...]float64{7.0, 8.5, 9.1}
1)type People interface {
SayHello()
ToString()
}
type Student struct {
Person
university string
course string
}
type Developer struct {
Person
company string
platform string
}
func main(){
alex := Student{Person{"alex", 21, "111-222-XXX"}, "MIT","BS CS"}
john := Developer{Person{"John", 35, "111-222-XXX"}, "Accel North America", "Golang"}
jithesh := Developer{Person{"Jithesh", 33, "111-222-XXX"}, "Accel North America", "Hadoop"}
//An array with People types
peopleArr := [...]People{alex, john,jithesh}
}
和float64{7.0, 8.5, 9.1}
这个语法是什么意思?看起来比语法更像是一种范式(一种编程方式)
2)您能否提供有关People{alex, john,jithesh}
语法的含义/目的的参考?我看到将某些内容转换为[...]
类型
答案 0 :(得分:0)
花括号用于定义复合文字。一个值,其中包含多个值。在您的第一个示例中,创建了一个浮点值数组
[...]float64{7.0, 8.5, 9.1}
是包含3个元素的浮点数组的文字。在第二个示例中,将创建一些用于预定义结构类型的文字,并创建另一个数组。 Person{"alex", 21, "111-222-XXX"}
是用于Person类型的结构的文字。 [...]People{alex, john,jithesh}
是People类型的数组,包含3个元素。